7 months ago

Call to a member function toArray() on null

Posted 7 months ago by swimmer

I built a nav bar and when a link is clicked I bring in from My SQL all the info Relevant to that page in my case the title and description.

However when someone clicks on a link that leads to a page that there is no information in the database I built on else that's states that "no information is available ." However my code gets stuck in the model stage when pulling the information from the database I get the following error: Call to a member function toArray() on null

This is my model code:


namespace App;

use Illuminate\Database\Eloquent\Model;

class content extends Model
    static public function getAll($url){
   if( !empty($menu= Menu::where('url', '=', $url)->first()->toArray())) {
    // $menu= Menu::where('url', '=', $url)->first()->toArray()) 
    $content = Content::where('menu_id', '=',$menu['id'])->get()->toArray();

    return $content;



What am I doing wrong?

Please sign in or create an account to participate in this conversation.