Hello Guest! Welcome to my website.

You can benefit from our privileges as a member of our site.

or Register

Question How do I wrap Laravel eloquent conditions to create the following query

admk

Member
Joined
Oct 10, 2021
Messages
46
Reaction score
2
Points
8
I have a simple results table that looks like the following -
Rich (BB code):
id, home_team_id, away_team_id, home_score, away_score, media
1       511          322            4           0       'a4vw'
2       232          511            2           2       'bf34',
3       111          511            2           3        NULL      

I am able to get all the rows where 'team_id' value is either the home_team_id OR away_team_id = 511, but I also need to check to ensure that the media column is NOT NULL The raw SQL query would like like this

SELECT * FROM results where (home_team_id = 310718 OR away_team_id = 310718) and media is not null;

However I am trying to use the Laravel Eloquent approach as much as possible as I'm learning this so could use one approach like the following (which works fine) but i'm trying to not use any DB::raw methods in my approach
PHP:
DB::table("results")
->where(DB::raw("(home_team_id = 511 or away_team_id = 511)"))
->whereNotNull("media")
->get();


How would I amend the following in my Results model to perform the same query as the queries above as this returns all the results I only expect 2 results as media column has a single NULL entry

PHP:
return Result::where('home_team_id', '=', $clubId)
             ->orWhere('away_team_id', '=', $clubId)
             ->whereNotNull('media')
             ->get();
 
Top