Eloquent: SQL Query with where or in brackets

If the query needs parentheses/brackets for a where condition like below Normal SQL:

SELECT * 
FROM  users
WHERE planet = 'earth'
AND (fname LIKE '%hawk%' OR lname LIKE '%hawk%')
AND state = 'FL'

ELOQUENT SQL:

$name = "hawk";

$usersResults = DB::table('users')
    ->where('planet', '=', 'earth')
    ->where(function($query) use ($name){
            $query->where('fname' , 'like', '%'.$name.'%');
            $query->orWhere('lname' , 'like', '%'.$name.'%');
      })
     ->where('state', '=', 'FL')
    ->get();

2 comments:

Python contextlib for Timing Python code

If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...