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();
Laravel eloquent multiple WHERE with OR AND OR and LIKE?
Use like
and not like
with %
in where()
and orWhere()
methods:
->where('column', 'like', '%pattern%')
https://laravel.com/docs/5.3/queries#where-clauses
If you need to use multiple AND
do like this:
->where($condition)
->where($anotherCondition)
If you want to use OR
do this:
->where($condition)
->orWhere($anotherCondition)
To combine multiple AND
and OR
do parameter grouping:
->where('name', '=', 'John')
->orWhere(function ($query) {
$query->where('votes', '>', 100)
->where('title', '<>', 'Admin');
})
Laravel 5: How to use 'where' or 'orderBy' using eloquent?
You can do it like this:
$ideas = $user->idea()
->where('status', '<>', 'DRAFT')
->orderBy('created_at', 'desc')
->get();
When you use ->idea()
it will start a query.
For more information about how to query a relationship: https://laravel.com/docs/5.7/eloquent-relationships#querying-relations
laravel querybuilder how to use like in wherein function
Thanks everyone for helping me but i solved it by doing:
$book = array('book2','book3','book5');
$name = DB::Table('bookinfo')
->select('BookName', 'bookId')
->Where(function ($query) use($book) {
for ($i = 0; $i < count($book); $i++){
$query->orwhere('bookname', 'like', '%' . $book[$i] .'%');
}
})->get();
Related Topics
I Cannot Get My Login Form to Connect Interact Properly With MySQL Database
Insert - Number of Bind Variables Doesn't Match Number of Fields in Prepared Statement
Laravel Certificate Verification Errors When Sending Tls Email
Sanitizing Strings to Make Them Url and Filename Safe
Upgrading PHP in Xampp For Windows
How to Prevent the "Confirm Form Resubmission" Dialog
PHP: Sort and Count Instances of Words in a Given String
Parentheses Altering Semantics of Function Call Result
What Are PHP Nested Functions For
PHP Sessions Timing Out Too Quickly
Use PHP to Set Cron Jobs in Windows
Export MySQL Data to Excel in PHP
How to Remove Extension from String (Only Real Extension!)
How to Get Rid of Eval-Base64_Decode Like PHP Virus Files
PHP Curl, Extract an Xml Response
Laravel Migration: Unique Key Is Too Long, Even If Specified