1

when ever i want to logout, it always show "Use of undefined constant login - assumed 'login'" error. what did i do wrong?

web.php

route::get('/logout','AuthController@logout')->name('logout');

route::get('/','PagesController@home')->name('home');

AuthController.php

public function getLogin(){
        return view('login');
    }

    public function postLogin(Request $request){
       if(!\Auth::attempt(['email' => $request->email, 'password' => $request->password])){
        return redirect()->back();
       }
        return redirect()->route('home');
    }

public function logout(){
        \Auth::logout();
        return redirect()->route(login);
    }

PagesController.php

public function home()
    {
        return view('index') ;
    }

main.blade.php

<a href="{{route('logout')}}">logout</a>
Lee wayy
  • 73
  • 1
  • 11

3 Answers3

4

Put login in qoutation:

public function logout(){
        \Auth::logout();
        return redirect()->route('login');
    }
Rouhollah Mazarei
  • 3,969
  • 1
  • 14
  • 20
3

As per your code you need to use quote for it on the below line while using login, so if you do not provide quote it is assuming as constant. And also there should be a route for it in your route file with the name login as per your question that route also do not exists yet

public function logout(){
        \Auth::logout();
        return redirect()->route('login');
    }
msonowal
  • 1,553
  • 3
  • 17
  • 36
3
public function logout(){
        \Auth::logout();
        return redirect()->route(login);
    }

change To :

public function logout(){
        \Auth::logout();
        return redirect()->route('login');
    }
Ramki
  • 452
  • 2
  • 16