I\'m confused as to when ->get()
in Laravel...
E.G. DB::table(\'users\')->find(1)
doesn\'t need ->get() to retrieve the results, neither
Since the find()
function will always use the primary key for the table, the need for get()
is not necessary. Because you can't narrow your selection down and that's why it will always just try to get that record and return it.
But when you're using the Fluent Query Builder you can nest conditions as such:
$userQuery = DB::table('users');
$userQuery->where('email', '=', 'foo@bar.com');
$userQuery->or_where('email', '=', 'bar@foo.com');
This allows you to add conditions throughout your code until you actually want to fetch them, and then you would call the get()
function.
// Done with building the query
$users = $userQuery->get();