mercredi 28 juin 2017

How to manage Login/Logout in laravel using Auth

I have create one login module in laravel,what i have done yet is i have manually authenticated the user successfully and redirect on dashboard page but my issue is when user logged out from the application and again if they try to open that dashboard url then it is showing error MethodNotAllowedHttpException in RouteCollection at this time what i want is if user is not authenticated then it will directly redirect on our login page.I have also tried to put some logic in my LoginController Constructor but it is also not working.Below is my code with file path.

laravelproject\app\Http\routes.php

Route::auth();
Route::post('/login-submit', 'LoginController@loginSubmit');
Route::get('/log-out',[
    'uses'=>'LoginController@logOut',
    ]);

laravelproject\app\Http\Controllers\LoginController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;

//to take input from user
use App\Http\Requests;
use Illuminate\Http\Request;
//end

class LoginController extends Controller
{


    public function loginSubmit(Request $request)
    {

         $email=$request->email;
         $password=$request->password;

         //var_dump($credentials);die;
        if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
            // Authentication passed...

             return view('dashboard');
        }
        else
        {
             return view('auth/login');
        }    
    }

    public function logOut() {


        Auth::logout();

        return view('auth/login');

    }
}

Error after getting logout and trying to accessing dashboard url MethodNotAllowedHttpException in RouteCollection



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire