mercredi 7 mars 2018

Laravel Many to Many relationship not working

Hi I am trying to get laravel manay to many relationship queries but not working. I have totally three tables with names campaign, campaign_tg and target_group with below DB schema

- campaign :: id, name

- campaign_tg :: target_level, campaign_id, tg_id

- target_group :: id, name, min and max

In campaign model i have created a relationship like below

public function tg()

{

    return $this->belongsToMany('App\Models\TargetGroup', 'campaign_tg', 'campaign_id', 'tg_id');

}

In the same way i have created another relationship in TargetGroup model like below

public function campaigns()

{

    return $this->belongsToMany('App\Models\TargetGroup', 'campaign_tg', 'tg_id', 'campaign_id');

}

Now i am trying to access the relationship like below but some how it's not working

Campaign::with('tg')->find(id);



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2G3VB9Y
via IFTTT

Aucun commentaire:

Enregistrer un commentaire