mercredi 2 décembre 2015

Create a lists of categories and their subcatgory in Laravel 5

i have three table as category,subcategory and subcategory_category that i store foreign key of other table in it i want to show a list with category and subcategory same as:

  • category1

    • subcategory1

    • subcategory2

  • category2

    • subcategory3

    • subcategory4

i try this it is not ok in my controller:

$mycategories = SubcategoriesCategories::with('parent')->with('children2')->get();

and in model:

class SubcategoriesCategories extends Model  {
protected $table = 'subcategories_to_categories';
public function parent()
{
    return $this->belongsTo('App\categories', 'categories_id');
}
    public function children2()
{
    return $this->belongsTo('App\subcategories', 'subcategories_id');
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire