I am trying to display category, subcategory, subsubcategory page but i am getting undefined offset:0 error when i am opening any page. Please let me know how i can show my data on a perticular page.
here is my controller GuidePagesController.php
public function categoryGuides(Request $r, $cat, $subcat=NULL,
$subsubcat=NULL){
$guidedata=GuidePages::all();
if($cat != NULL && $subcat != NULL && $subsubcat != NULL){
$cat = Category::where('slug',$cat)->get();
$subcatid = Subcategory::where('slug',$subcat)->get();
$subsubcatid = SubSubcategory::where('slug',$subsubcat)->get();
$guides = GuidePages::where(function($q) use($cat, $subcatid,
$subsubcatid)
{
$q->where('category_id','=', $cat[0]->id)
->where('subcategory_id','=', $subcatid[0]->id)
->where('subsubcategory_id','=', $subsubcatid[0]->id);
})->orderBy('id','desc')->paginate(8);
}
elseif($cat != NULL && $subcat != NULL){
$cat = Category::where('slug',$cat)->get();
$subcatid = Subcategory::where('slug',$subcat)->get();
$guides = GuidePages::where(function($q) use($cat, $subcatid){
$q->where('category_id','=', $cat[0]->id)
->where('subcategory_id','=', $subcatid[0]->id);
})->orderBy('id','desc')->paginate(8);
}
else{
$cat = Category::where('slug',$cat)->get();
$guides = GuidePages::where('category_id','=', $cat[0]->id)-
>orderBy('id','desc')->paginate(10);
}
$data=['guidedata'=>$guidedata,'guides'=>$guides,'cat'=>$cat[0]-
>category_name,];
return view('guide-pages', $data);
}
And here is my route:
Route::get("category/{cat}/{subcat?}/{subsubcat?}", ["uses" => "GuidePagesController@categoryGuides", "as" => "category.cat.product"]);
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire