Complete the code to start a query using Laravel's Query Builder.
$users = DB::[1]('users')->get();
The table method starts a query on the specified table, giving flexibility to build queries.
Complete the code to add a condition to the query.
$users = DB::table('users')->where('[1]', 'active')->get();
The where method filters results. Here, filtering users with status equal to 'active' shows flexibility in conditions.
Fix the error in the code to chain multiple conditions.
$users = DB::table('users')->where('status', 'active')->[1]('age', '>', 18)->get();
To add multiple conditions that all must be true, chain where methods. This shows flexibility in building complex queries.
Fill both blanks to select specific columns and order results.
$users = DB::table('users')->[1](['name', 'email'])->orderBy('[2]', 'desc')->get();
The select method chooses columns to retrieve, and orderBy sorts results by a column like created_at. This flexibility lets you customize output.
Fill all three blanks to group results, count users, and filter groups.
$results = DB::table('users')->select('[1]', DB::raw('[2] as user_count'))->groupBy('[3]')->having('user_count', '>', 5)->get();
This query groups users by status, counts users in each group, and filters groups with more than 5 users. Query Builder's flexibility allows such complex queries easily.