867
views
views
There is an easy way of doing multiple "where" with eloquent
Suppose you want to have something like
SELECT * FROM `users`WHERE`name` = 'some_name' AND `email` = 'some_email' LIMIT 1
You could write:
\App\User::where('name', 'some_name')->where('email', 'som@_email')->first();
or
\App\User::where(['name' => 'some_name', 'email' => 'some@email'])->first();
but you can achieve this really easily with
\App\User::whereNameAndEmail('some_name','some@email')->first();
Change Name and Email as required - the important part is the And between them. Laravel will automatically work out what columns your where statement refers to.
Comments
0 comment