Did you imported your Menu Model in the top of your Controller? e.g
// or what ever the Namespace of Menu is
use App\Menu
....
I've got a helper.php where I put code that I plan on reuseing. I'm trying to get a function to work but I'm getting this error
FatalErrorException in helpers.php line 90:
Class 'Menu' not found
This is my code
function getSeoLink($page_id)
{
$menu = Menu::where('id', $page_id)->firstOrFail();
foreach($menu->seo as $seo){
$seo = $seo->url;
}
if(empty($seo)){
return '/'.$page_id;
}
if(!empty($seo)){
$url = (!empty($seo) ? '/'.$seo : '/'.$page_id);
return $url;
}
return $url;
}
and line 90 is
$menu = Menu::where('id', $page_id)->firstOrFail();
Just a small addition to @christopher solution, just as an alternative.
$menu = App\Menu::where('id', $page_id)->firstOrFail();
I prefer this if I'm only referring that class once or twice, but if I need it more, I go with the use App\Model
Please or to participate in this conversation.