Wherehas in Laravel Eloquent
Syntax
$response = Model::with('relationships ')
->whereHas('relationships', function ($q) use ($pera) {
$q->where('relationships_table_name.id','=',$pera);
})
->get();
Use for Users Model
Example 1 :
$response = User::with('details')
->whereHas('details', function ($q) use ($pera) {
$q->where('user_details.id','=',$pera);
})
->get();
0 Comments