samedi 19 décembre 2015

laravel5 link tables in eloquent (foreign key)

I've got a transactions table containing transactions made by a user in the following style:

id|user_id|amount|method|...

Now I've got a table called "payment_methods" containg the payment methodes "as strings" like in following style: id|name

Content of the "payment_methods" table is like:

1 PayPal

2 credit card

I already linked the id of payment_methods to the "method" field of transactions using SQL. After this I created model. My User model is looking like:

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

My transaction and payment_methodes model is empty. How can I now link them, so I can easily call

 {{ $transaction->method }}

in my view getting the name of the payment method, not only a number.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire