Laravel-5 'LIKE' equivalent (Eloquent) Laravel-5 'LIKE' equivalent (Eloquent) php php

Laravel-5 'LIKE' equivalent (Eloquent)


If you want to see what is run in the database use dd(DB::getQueryLog()) to see what queries were run.

Try this

BookingDates::where('email', Input::get('email'))    ->orWhere('name', 'like', '%' . Input::get('name') . '%')->get();


I have scopes for this, hope it help somebody.https://laravel.com/docs/master/eloquent#local-scopes

public function scopeWhereLike($query, $column, $value){    return $query->where($column, 'like', '%'.$value.'%');}public function scopeOrWhereLike($query, $column, $value){    return $query->orWhere($column, 'like', '%'.$value.'%');}

Usage:

$result = BookingDates::whereLike('email', $email)->orWhereLike('name', $name)->get();


$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();