@Shawdow
$subcategory = \App\Product::where('id',$id)->where('name',$name)->first();
$subcatdata = DB::table('categories')->select('*')->get();
$product = DB::table('products')->select('*')->where('category_id','=',$id)->get();
$prod = \App\Product::get();
$subids = $prod->pluck('attribute_id');
$attribute = \App\Attribute::whereIn('id', $subids)->get();
$brand = DB::table('brands')->select('*')->get();
these things r common shouldnt come in if or else, inside if u have to filter these according to filter value and return json response, in else u should return view
public function showsubcategory($id,$name,Request $request){
$subcategory = \App\Product::where('id',$id)->where('name',$name)->first();
$subcatdata = DB::table('categories')->select('*')->get();
$product = DB::table('products')->select('*')->where('category_id','=',$id)->get();
$prod = \App\Product::get();
$subids = $prod->pluck('attribute_id');
$attribute = \App\Attribute::whereIn('id', $subids)->get();
$brand = DB::table('brands')->select('*')->get();
if($request->ajax()) {
// filter the above data by filter request and return json response like
if($request->price) {
//filter the product by price
$product = $product->where('price', $request->price); // this collection where
}
return [
"product" => $product,// if you filter some other variable send those things too
];
}
else {
return \view ('subcategory',compact('product','subcatdata','attribute', 'brand','catid'));
}
}
R u creating e-commerce website?