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 Get Data On Conditions

I have 2 tables called movies and movie_dates.

In movie_dates table these are the fields,

id | movie_id | year | month

My Question: I’m trying to get data from the movies table where year is greater than or equal to 1 and month is greater than or equal to 2 in the movie_dates table using movie_id column.

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

What I tried so far,

$months = 2;
$years = 1;

return DB::table('movie_dates')
  ->join('movies', 'movie_dates.movie_id', '=', 'movies.id')
  ->where(['movie_dates.year', '>=', $years], ['movie_dates.month', '>=', $months])
  ->get();

Error I’m getting : SQLSTATE[42S22]: Column not found: 1054 Unknown column

Really appreciate it if somebody could help me. Thanks have a nice day.

>Solution :

Use array on where

$months = 2;
$years = 1;

return DB::table('movie_dates')
  ->join('movies', 'movie_dates.movie_id', '=', 'movies.id')
  ->where([['movie_dates.year', '>=', $years], ['movie_dates.month', '>=', $months]])
  ->get();
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