Multiple WHERE
Multiple WHERE
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.

What's your reaction?

Comments

https://www.magazine.tdbcomputing.com/assets/images/user-avatar-s.jpg

0 comment

Write the first comment for this!

Facebook Conversations

Disqus Conversations