Answer the question
In order to leave comments, you need to log in
Is it possible to access related model properties in a query?
Guys, a question about Eloquent .
There is a Visit entity (visit), it is connected one to one with the Claim entity (complaint).
I want to pull out a complaint with one request through Eloquent, which has some Visit fields in certain values. That is - "Display complaints that have visit.ip = 127.0.0.1"
Example:
visits
id | ip | created_at
1 | 127.0.0.1 | 2016-01-01
2 | 192.168.0.1 | 2016-31-31
id | reason | visit_id
1 | Spam | 1
2 | Bad quality | 2
\Model\Claim::with("visits")->where('visits.ip', 'like', '127.0.0.1')->get();
Answer the question
In order to leave comments, you need to log in
// Retrieve all posts with at least one comment containing words like foo%
$posts = Post::whereHas('comments', function ($query) {
$query->where('content', 'like', 'foo%');
})->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question