Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel Eloquent how to use && or AND inside single WHERE clause

I am trying to make a query using Eloquent Model in Laravel.

My original query does not work

Query1::where('Course_ID', '=', $request->FLA)
->where('Date', '=', Carbon::today())

I would like the query to include both inside of a single WHERE, akin to:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Query1::where('Course_ID', '=', $request->FLA && 'Date', '=', Carbon::today())

Is this possible?

>Solution :

You can use:

Query1::where([
   'Course_ID' => $request->FLA,
   'Date' => Carbon::today()
]);

It will create the following SQL query:

SELECT * FROM tablename WHERE Course_ID = ? AND Date = ?

But your approach, using two ‘where’s will have the same output

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading