Ashkru
Ashkru

Reputation: 1635

WHERE and WHERE or WHERE Laravel Query?

I am trying to do a "WHERE AND WHERE OR WHERE" query with laravel, basically what I want to do is get all the events where the user_id equals a certain something AND where type = 'something1' OR 'something2' but right now the event is now only showing for the user_id its for but every user id?

I am trying to get financial events for a specific user:

App\Database\Website\Roleplay\Life\LifeEvents::where('user_id', $viewPlayer->id)->where('event_type', 'gained_money')->orWhere('event_type', 'lost_money')

Upvotes: 0

Views: 1365

Answers (2)

Hüseyin Dursun
Hüseyin Dursun

Reputation: 600

Try this:

App\Database\Website\Roleplay\Life\LifeEvents::where('user_id', $viewPlayer->id)
->where(function($where) {
      $where->where('event_type', '=', 'gained_money')
            ->orWhere('event_type', '=', 'lost_money')
});

Upvotes: 2

esemve
esemve

Reputation: 360

https://laravel.com/docs/5.4/queries

App\Database\Website\Roleplay\Life\LifeEvents::where('user_id', $viewPlayer->id)
       ->where(function($query) {
              $query->where('event_type', 'gained_money')
              ->orWhere('event_type', 'lost_money'); 
});

Upvotes: 0

Related Questions