Reputation: 2958
I have two table named user
and customer
.
The relation is user.id = customer.user_id
.
Now I want to select from customer
model on the basis of Parent model (user
), like this select c.* from customer as c inner join user as u ON c.user_id = u.id WHERE u.status = '1'
Now how to do that with laravel eloquent
Upvotes: 0
Views: 46
Reputation: 146239
You may try this:
$customers = Customer::whereHas('user', function($q) {
$q->where('status', 1);
})->get();
Also make sure you have user
method declared in your Customer
Model:
public function User()
{
return $this->belongsTo('user','user_id','id');
}
Upvotes: 1