php - Laravel : One is to Many Relationship, get foreign key value -


i'm working on productcategories , products relationship one many. wonder why i'm having error

call undefined method stdclass::products()

here's model products

<?php  namespace app; use illuminate\database\eloquent\model; class product extends model {   public $table = "products";   public $fillable = ['productcategory_id',                     'name',                     'description',                     'price',                     'pic',                     'availability',                     'featured',           ];   public function productcategory()   {       return $this->belongsto('app\productcategory');   } } 

and here's model product category

<?php  namespace app;  use illuminate\database\eloquent\model;  class productcategory extends model {   public $table = "productcategories";   public $fillable = ['name',                     'description',];   public function products(){       return $this->hasmany('app\product','productcategory_id','id');   } } 

and here's view file

@foreach($productcategories $productcategory)    @foreach($productcategory->products() $product)       {{ $product->name }}      @endforeach  @endforeach 

please me i'm getting error time.

just shooting in dark here, first remove parentheses in view file $productcategory->products(). if doesn't solve issue, dd($productcategories) in controller , verify you're passing collection of productcategory wouldn't expect resulting error include reference "stdclass".


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -