I use the following construction for joining tables: with(\"attachments\", \"offers.publisher\").
public function publisher()
{
retu
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
The best way would to just have two definitions, publishers
for all publishers, and active_publishers
for those with status = 1
:
public function publisher()
{
return $this->belongsTo("App\User", "user_id", "id");
}
public function active_publisher()
{
return $this->publisher()->where('status', 1);
}
Use with $object->active_publisher()->get();