samedi 2 mars 2019

Retrieving eloquent relationship with laravel

When I try to get the name of the Category from my product, I discovered I had to use a 'C' rather than a 'c' before it retrieved results. However when I try to get the Supplier name, the lowercase s works just fine. I was wondering what is causing this difference. Also if I dd($var), is the relations field expected to be empty. I assumed it would have something related to the relationships defined in my models.

Blade.php

  <td></td>
     <td></td>
     <td></td>
 <td></td>

Product.php

 public function category()
    {
        return $this->belongsTo('App\Category','category');
    }
 public function supplier()
    {
        return $this->belongsTo('App\Supplier','supplier_id');
    }

Category.php

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

Supplier.php

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire