Laravel where on relationship object

前端 未结 6 790
余生分开走
余生分开走 2020-12-12 20:21

I\'m developing a web API with Laravel 5.0 but I\'m not sure about a specific query I\'m trying to build.

My classes are as follows:

class Event exte         


        
6条回答
  •  臣服心动
    2020-12-12 20:44

    The correct syntax to do this on your relations is:

    Event::whereHas('participants', function ($query) {
        return $query->where('IDUser', '=', 1);
    })->get();
    

    Read more at https://laravel.com/docs/5.8/eloquent-relationships#eager-loading

提交回复
热议问题