Laravel Equivalent to 'LIKE' Operator in Eloquent
In Laravel 5, the equivalent of the 'LIKE' operator in MySQL is 'orWhereLike'. However, users may encounter issues when utilizing 'orWhereLike' to match results.
Correct Syntax
To accurately match results, ensure the 'orWhereLike' syntax follows this pattern:
Model::where('column_name', 'like', '%search_term%')
Example
In your specific case, to retrieve data similar to your MySQL statement, adjust your code as follows:
BookingDates::where('email', Input::get('email')) ->orWhere('name', 'like', '%' . Input::get('name') . '%') ->get();
Checking Queries
If you wish to verify the queries generated by Eloquent, employ the 'dd(DB::getQueryLog())' function to display the executed database queries.
The above is the detailed content of How to Use the Laravel Eloquent Equivalent of MySQL\'s LIKE Operator?. For more information, please follow other related articles on the PHP Chinese website!