Setup Laravel Authentication


Updated: 2019-02-24

Laravel Authentication

Create authentication files.

Setup Laravel Error Pages

Publish error pages.

Setup Admin Users

Add admin and default types to your User model (User.php).

const ADMIN_TYPE = 'admin';
const DEFAULT_TYPE = 'default';

public function isAdmin()    {
    return $this->type === self::ADMIN_TYPE;

Add type to your RegisterController.php create function.

protected function create(array $data)
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
        'type' => User::DEFAULT_TYPE

Create a Middleware to check if a user is an admin.

Update the Middleware like this:

namespace App\Http\Middleware;
use Closure;
class IsAdmin
     * Handle an incoming request.
     * @param    \Illuminate\Http\Request  $request
     * @param    \Closure  $next
     * @return  mixed
    public function handle($request, Closure $next)
        if(auth()->user()->isAdmin()) {
            return $next($request);
        return redirect('home');

Register the middleware. Update app/Http/Kernel.php section $routeMiddleware with:

    'is_admin' => \App\Http\Middleware\IsAdmin::class,
public function __construct()