Create Custom Authentication Laravel

kontol-mabur-1

Apr 15th, 2017 01:25 AM

My project recently done, But my client request to change some function like login, my client request 'suspend' feature to users, I Know its can be done with this https://laravel.com/docs/5.4/authentication#authenticating-users but I already using default authentication provide by Laravel, My question is, is podible to use this: https://laravel.com/docs/5.4/authentication#authenticating-users on my existing application?

devdojo

Apr 15th, 2017 07:24 PM

Yeah, you can totally do this with the function. You will probably want to create a new row in the database that is a boolean type and it can be a 0 by default. So, if the user is suspended, this will be a 1. You could call this row suspended and you should be able to do something like this:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    /**
     * Handle an authentication attempt.
     *
     * @return Response
     */
    public function authenticate()
    {
        if (Auth::attempt(['email' => $email, 'password' => $password])) {
            // Authentication passed...
            if(Auth::user()->suspended){
                return redirect('account-suspended');
            }
            return redirect()->intended('dashboard');
        }
    }
}

Let me know if that helps :)

Thanks.

kontol-mabur-1

Apr 17th, 2017 06:09 AM

Thanks worked perfectly! ^^

jeanclaude-mbiya

Oct 23rd, 2019 11:43 AM

Hi, i'm new in laravel and i have tried to use the laravel auth system in my app, with everything default ( routes, controllers..) please i want to know i can change or customise the verify email routes and also customize all the default auth. thanks