How to use the Larave DB Facade to get the first record with a date close to a particular date

  database, eloquent, laravel, orm, php

I am trying to get the first transaction that was recorded close to a particular date using the Laravel 8 DB Facade.

I have tried to use it in the following manner

       $lastest_transaction = DB::table($targetTable)
        ->where('date', '<=', date('F'))
        ->where('id', '=', $client->id)
        ->where('branch', '=', session('branch'))
        ->get();

but it’s not giving me the correct transaction.

Source: Laravel

Leave a Reply