mardi 1 septembre 2015

Laravel working with relations

I've three tables called:"

User Rittenregistratie karakterrit

A user has one or multiple Rittenregistratie and a Rittenregistratie has one Karakterrit.

This are my models:

User model:

  public function Rittenregistratie()
    {
        return $this->hasMany('App\Rittenregistratie');
    }

Rittenregistratie model:

 public function User()
    {
        return $this->belongsTo('App\User');
    }

    public function karakterrit()
    {
        return $this->hasOne('App\karakterrit');
    }

Karakterrit model:

public function rittenregistratie()
    {
        return $this->belongsTo('App\rittenregistratie');
    }

When I search for a specific id in my controller for the rittenregistratie I do it like this:

$rittenregistratie = Rittenregistratie::whereId($id)->firstorFail();

And when I want to show the karakterrit of that rittenregistratie in my view I do it like this:

$rittenregistratie->karakterrit_id

But how do I make sure that I don't see a number but the value from that row?



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

Aucun commentaire:

Enregistrer un commentaire