Newbie
Newbie

Reputation: 11

"Trying to get property of non-object" Laravel

i have some problem... here is my code.. i can't get what i swrong with my code.....

here is the error here is my user class

this is the full DashboardController

/**
 * '/home' calls this route
 *
 * @param none
 * @return view dashboard
 */
public function index()
{
    $this->permission();
    $data = [
        'pagetitle' => 'Dashboard',
        'permission' => Session()->get('permission'),
        'name' => Auth::user()->name,
    ];
    return view('dashboard',$data);
}


/**
 * Checks if session has permission in it if not they adds to it
 *
 * @param null
 * @return null
 */
private function permission()
{
    if (!Session()->has('permission')) {
        $permission = User::find(Auth::user()->id)->details;
        $permission_arr = [
            'department' => $permission->permission_department,
            'asset' => $permission->permission_asset,
            'users' => $permission->permission_users,
        ];

        Session()->put('permission', $permission_arr);
    }
}

}

i have no idea how solve it.. any help would be great..

Upvotes: 1

Views: 77

Answers (1)

MD. Jubair Mizan
MD. Jubair Mizan

Reputation: 1560

You get this kind of problem for you are getting only access of details column From your User table . Remove the details from $permission = User::find(Auth::user()->id);

private function permission(){
  if (!Session()->has('permission')){
     $permission = User::find(Auth::user()->id);
     $permission_arr = [
        'department' => $permission->permission_department,
        'asset' => $permission->permission_asset,
        'users' => $permission->permission_users,
     ];

     Session()->put('permission', $permission_arr);
  }
}

Note I have only remove the details object from your permission variable

Upvotes: 1

Related Questions