Answer the question
In order to leave comments, you need to log in
Condition for with in laravel?
Tell me how to set the condition correctly.
There are two entities
#
class Journal {
public function posts()
{
return $this->hasMany('App\Models\Post');
}
}
class Post {
public function journal()
{
return $this->belongsTo('App\Models\Journal');
}
}
$posts = Post::with('journal')->get();
Journal::with('posts')->where('name', 'someValue');
Answer the question
In order to leave comments, you need to log in
$posts = Post::with('journal')->whereHas('journal', function ($query) {
// some query
}])->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question