This question already has an answer here:
I was wondering how I can access table information from a belongsToMany relationship in Laravel.
I currently access all addons of a specific activity using a belongsToMany relationship, the code looks like this:
Activity.php
public function addons(){
return $this->belongsToMany( 'App\Models\Addon', 'na_activity_addon', 'activity_id', 'addon_id');
}
Addon.php
public function activity()
{
$this->belongsToMany('App\Model\Activity', 'na_activity_addon', 'addon_id', 'activity_id');
}
I access the code like this, which works just fine:
$activity = Activity::findOrFail($id);
$addons = $activity->addons->all();
With this I receive all the addons for that specific activity.
Now, what I want to do, however, is get all addons that are NOT assigned to this activity, but are still belonging to the specific user who has this activity.
How would I need to set this relationship up?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2DN16sh
via IFTTT
Aucun commentaire:
Enregistrer un commentaire