hello m trying to get categories/products seprately, like when i click on specific category then its related products shown:
but it says: Call to undefined relationship [categories] on model [App\Category].
actually my categories starts from "8" when i type 8 to replace 0 then it shows : Undefined variable: categoriesDetails
categories = Category::with('categories')->where(['parent_id'=>0])->get();
code of ProductsController:
public function products($url = null){
$categories = Category::with('categories')->where(['parent_id'=>0])->get();
$categoryDetails = Category::where(['url' => $url])->first();
$productsAll = Product::where(['category_id' => $categoriesDetails->id])->get();
return view('products.listing')->with(compact('categories','categoryDetails','productsAll'));
}
code of Product model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
public function category(){
return $this->belongsTo('App\Category');
}
}