Laravel eloquent where like query
The Eloquent WHERE LIKE method on a query builder instance to add where clauses to the query.
His first argument is the name of the column. His first contention is the name of the section. The subsequent contention is an administrator, which can be any of the database’s upheld administrators.
Laravel Query
public function search(Request $request) {
$search = $request->s;
$students = tablename::where('userId', 1)
->where(function($query) use ($search) {
$query->where('name', 'LIKE', '%'.$search.'%')
->orWhere('email', 'LIKE', '%'.$search.'%');
...
})
->paginate(10);
}
SQL Query
SELECT * FROM tablename WHERE tablename.userId = $id AND (tablename.name like '%$search%' OR tablename.email Like '%$search%')