Answer the question
In order to leave comments, you need to log in
Condition in eloquent?
Hello, help me add a condition.
There are users, magazines and articles. Journals publish articles, and users read them and can add them to favorites.
Models:
#
class User {
public function posts()
{
return $this->belongsToMany('App\Models\Post')->withTimestamps();
}
}
class Journal {
public function posts()
{
return $this->hasMany('App\Models\Post');
}
}
class Post {
public function journal()
{
return $this->belongsTo('App\Models\Journal');
}
}
#
auth()->user()->with(['posts' => function($query) {
$query->conditions();
}])
#
auth()->user()->with(['posts.entity' => function($query) {
$query->conditions();
}])
#
auth()->user()->with('posts.entity')
Answer the question
In order to leave comments, you need to log in
auth()->user()->with(['posts' => function($query) {
$query->with('entity')->conditions();
}])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question