Click here to Skip to main content
15,881,866 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I got some issue on laravel with this code > for logincontroller

in database I was using char for level as called for admin and user. and the code I build like this


-----------

when to run this got error > `ErrorException
Attempt to read property "level" on null`


hope can help me solved this. thanks

What I have tried:

PHP
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
class LoginController extends Controller
{
    
    public function index(){
        return view('auth.login');
    }
    
    
    public function store(Request $request){
     
        if(Auth::user()->level==admin){
            return view('admin.admin-home',[
            
            ]);
        }else{
            (Auth::user()->level==user);
            return view('user.user-home'
  
            );
        }
         
     
     return back()->with('alert',[
         'type' => 'danger',
         'msg' => 'There is wrong in your credentials!'
     ]);
    }    
    
}
Posted
Updated 24-Aug-22 22:00pm
v2

1 solution

Python
if(Auth::user()->level==admin){

The message is telling you that the call to Auth::user() does not return anything. So you need to use the debugger to find out why.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900