I have category table which has parent_category_id column since each category can have more than sub category so I in my Category model:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
//
public function subCategories(){
$this->hasMany('App\Category', 'parent_category_id');
}
public function products(){
$this->hasMany('App\Product');
}
public function parentCategory(){
$this->belongsTo('App\Category', 'parent_category_id');
}
but when I try Category::where('parent_category_id', null)->where('is_hidden', 0)->subCategories()->get()
all I get Call to undefined method Illuminate\Database\Eloquent\Builder::subCategories()"
how to solve this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire