$maincategory = Category::all(['id', 'category']);
$maintable = Category::orderBy('id', 'DESC')->get();
$subcategory = Subcategory::all(['id', 'subcategory']);
$subtable = Subcategory::orderBy('id', 'DESC')->get();
return view('admin.news.create', compact('maincategory', $maincategory, 'maintable','subcategory',$subcategory,'subtable'));
am getting error on this
return view('admin.news.create', compact('maincategory', $maincategory, 'maintable','subcategory',$subcategory,'subtable'));
how to solve it?
2
Answers
You can not use query result collection in
compact
.Here
compact('maincategory', ...)
will send$maincategory
andsubcategory
will send$subcategory
to the viewadmin.news.create
.You can also use with() like this
You can access it like this in your view blade
The error says: compact: must be string or string of Array, so, if your
variables
are more than one, pass it this way:But if your
variable
is just one, then thats when you usestring