I have two functions
whatsnew()
and
perfume()
both has its own @foreach
in different sub folders which i show them in one page.
problem is if one @foreach
works the other show an error undefined variable
ps- this is my first time posting a question in SO .. sorry if its sloppy..
ProductController.php
//to show last 5 latest items
public function whatsnew(){
$cat_new = products::orderBy('id', 'desc')->take(5)->get();
return view('/home', compact('cat_new'));
}
//to show category
public function perfume(){
$perfume = products::where('category','LIKE','perfume')->get();
return view('/home', compact('perfume'));
}
Web.blade.php
Route::get('/', [
'uses' => 'ProductController@whatsnew',
'as' => 'db.whatsnew']);
Route::get('/', [
'uses' => 'ProductController@perfume',
'as' => 'db.perfume']);
perfume.blade.php
@foreach($perfume as $perfume_cat)
whatnew.blade.php
@foreach($cat_new as $row)