Search code examples
laravellaravel-artisantinker

How to get all records which meet a Criteria in Laravel Tinker?


I can get the first user, who is an admin in Laravel's tinker using the following command:

$adminUser = App\User::where('is_admin',true)->first();

How do I get all the users which meet this where criteria?


Solution

  • Just change first() to get().

    $adminUser = App\User::where('is_admin',true)->get();

    first() is used when you want to retrieve single row or column. where get() is used to retrieve all rows.

    just go through the laravel official documentation database query builder section here. It will give you information regarding most of every possible things you can playoff with laravel.