How to set where in relation Laravel?

前端 未结 2 956
死守一世寂寞
死守一世寂寞 2021-01-15 16:21

I use the following construction for joining tables: with(\"attachments\", \"offers.publisher\").

public function publisher()
    {
        retu         


        
2条回答
  •  生来不讨喜
    2021-01-15 17:08

    Here is link that can help you:

    Please check this:

    Eloquent where condition based on a "belongs to" relationship

    Also you can do like this:

    Suppose you have a post modal and each post has many comment. So can get the condition matching post comments by as following with where conditions

     public function comments()
    {
        return $this->hasMany('App\Comment');
    }
    
     App\Post::find(1)->comments()->where('title', 'foo')->get();
    

    Thanks

提交回复
热议问题