dimanche 18 septembre 2016

Laravel 5.2 logout() is not working

when i use make:auth on command to create simple authorize pages, i can loggin and register successful, but when i try to click on logout i get error, i used latest upadte laravel 5.2 and this is my AuthController:

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Validator;

class AuthController extends Controller
{
    use AuthenticatesAndRegistersUsers, ThrottlesLogins;
    protected $redirectTo = '/home';

    public function __construct()
    {
        $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
    }

    protected function validator(array $data)
    {
        return Validator::make($data, [
            //@formatter:off
                'username'      => 'required|max:255',
                'name'          => 'required|max:255',
                'email'         => 'required|email|max:255|unique:users',
                'password'      => 'required|min:6|confirmed',
            //@formatter:on
        ]);
    }

    public function getLogout()
    {
            auth()->logout();

            return redirect()->route('/home');
    }  

    protected function create(array $data)
    {
        return User::create([
            //@formatter:off
            'username'  => $data['username'],
            'name'      => $data['name'],
            'email'     => $data['email'],
            'password'  => bcrypt($data['password']),
            //@formatter:on
        ]);
    }
}

i read more and more topic which have this problem, but solutions couldn't resolve my problem as adding

Route::get('auth/logout', 'Auth\AuthController@logout');

on routes or use middleware on constructor:

$this->middleware($this->guestMiddleware(), ['except' => 'logout']); 

my link to logout on layout is:

<li><a href=""><i class="fa fa-btn fa-sign-out"></i>Logout</a></li>

and i get this error:

NotFoundHttpException in compiled.php line 8912:

full stack error:

in compiled.php line 8912
at RouteCollection->match(object(Request)) in compiled.php line 8264
at Router->findRoute(object(Request)) in compiled.php line 8212
at Router->dispatchToRoute(object(Request)) in compiled.php line 8207
at Router->dispatch(object(Request)) in compiled.php line 2419
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 3286
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9963
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in compiled.php line 9948
at Pipeline->then(object(Closure)) in compiled.php line 2366
at Kernel->sendRequestThroughRouter(object(Request)) in compiled.php line 2350
at Kernel->handle(object(Request)) in index.php line 54



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire