like in query builder laravel code example

Example 1: add like and equal in same query in laravel

$data = DB::table('borrowers')
        ->join('loans', 'borrowers.id', '=', 'loans.borrower_id')
        ->select('borrowers.*', 'loans.*')   
        ->where('loan_officers', 'like', '%' . $officerId . '%')
        ->where('loans.maturity_date', '<', date("Y-m-d"))
        ->get();

Example 2: laravel where like

$users = DB::table('users')
                ->where('name', 'like', 'T%')
                ->get();

Example 3: laravel orWhere

$camps = $field->camps()->where('status', 0)->where(function ($q) {
    $q->where('sex', Auth::user()->sex)->orWhere('sex', 0);
})->get();

Tags:

Php Example