I have an instance of $personof Personand you want to check if the relation created for the external object ( App) exists .
people: id
people_apps: person_id, app_id
apps: id
Relationships are displayed correctly in Eloquent models. What is the preferred way to test this?
The only way I can think of is something like
$foundApp = $person->apps->filter(function($a) use($searchAppId)
{
return $a->id == $searchAppId;
});
if ($foundApp) {}
but probably the best way.
source
share