Multiple Authentication in Laravel 5.4 Natively! (Admins + Users) - Part 1

DevMarketer · 414K views · 2017 · 32:56

Open on YouTube

Web developmentPython, Ruby & scripting languagestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering how to set up multi-auth in Laravel with separate guards and user tables, since the official docs covered this poorly.

Recommended by 6 people across 6 different months, 2017 to 2021.

What it is

A 33-minute Laravel 5.4 tutorial by DevMarketer, the first of a series, showing how to support multiple user models (for example admins and regular users) with separate tables, guards and middleware using only Laravel's native auth. Part 1 covers setting up the models and auth guards.

What people said

Strong rec Dhruv Vadodariya · 2019-06 · Stack Overflow · on “Laravel Auth return to index”

for admin user you can create 'admin' guard.. here a link for multiauth in laravel. This tutorial is amazing.. if you are beginner than you should check this out..https: [this video]

Recommends Abid Raza · 2017-11 · Stack Overflow · on “Two different models for authentication in laravel 5.4”

I wanted to but its the exact same answer. It will be same as long as in given answer. I will try to explain it in short steps but, here are some tutorials links [this video] and [LINK]

Recommends ronrun · 2018-03 · Stack Overflow · on “Laravel 5.5, Auth::user() not working in Controller.php”

I follow the video Multiple Authentication in Laravel 5.4 Natively! (Admins + Users) - Part 1 [this video] From part1 to 5, it's all done. Now I can login, logout. Buy when I want to get the admin's properties, I got problem. In admin blade, I can use {{ Auth::user()->name }}, it's ok. In Composer, it's also ok. <?php namespace App\Http\ViewComposers; use Illuminate\View\View; use Illuminate\Http\Request; use Auth; class AdminComposer { /** * Create a movie composer. * * @return void */ public function __construct(Request $request) { $this->admin= Auth::user(); $this->base = config('app.url') . '/admin/'; } /** * Bind data to the view. * * @param View $view * @return void */ public function compo

Recommends DongHyun Kim · 2018-08 · Stack Overflow · on “multi auth laravel 5.6 step by step for beginner”

This guy rocks...I learned how to do multi auth with this youtube video, it's little bit long but it will surely get you to making authentication for both Admin and User if that's what you want. [this video] This is a cheat sheet I made for this tutorial video. Reference it when you get too tired of typing everything on the video. However, I strongly recommend watch the video, just looking at these instructions might be not enough. Basic Auth & Admin Model php artisan make:auth php artisan make:migration create_admins_table --create=admins database/migrations/???_create_admins_table.php public function up() { Schema::create('admins', function (Blueprint $table) { $table->increments('id'); $table-

Recommends Dhruv Vadodariya · 2019-06 · Stack Overflow · on “How to set default redirect with different session on laravel 5.8”

I think you should create multiple guards according to roles name like 'admin','superamdin'. Here is link for create multiauth in laravel . [this video] After your create multiple guards you can just use middleware to redirect authenticated user. public function handle($request, Closure $next, $guard = null) { switch ($guard) { case 'admin': if (Auth::guard('admin')->check()) { return redirect()->route('admin.dashboard'); } break; case 'superadmin': if (Auth::guard('superadmin')->check()) { return redirect()->route('superadmin.dashboard'); } break; default: //user gaurd if (Auth::guard($guard)->check()) { return redirect('/'); } break; } return $next($request); } Second Option Store authenticatio

Recommends Pamela Chup · 2021-01 · Stack Overflow · on “Laravel 7 - How to use other table except users table for login?”

You can create a different authentication guard in the config/auth.php file, the new guard needs to use your table. Then in the model for that table extend the lluminate\Foundation\Auth\User class. Maybe this help [this video] Also your login controller needs to use the custom auth guard.

Recommends Dennis · 2021-11 · Stack Overflow · on “Laravel Reset Password Error, Attribute Email is not in user entity”

Well, it is hard to understand if you've never worked with this part of the framework before but maybe you will understand it a bit more by watching this YouTube series about it: [this video] Even if it's published 4 years ago, I think you will learn from it.

Cites Mutasim Fuad · 2017-05 · Stack Overflow · on “How to perform multi auth in laravel?”

In your auth.php file add providers in providers array for defined guards. 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', //'provider' => 'employees' ], 'api' => [ 'driver' => 'token', 'provider' => 'users', //'provider' => 'employees' ], 'employees' => [ 'driver' => 'session', 'provider' => 'employees', ], ], 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\User::class, ], 'employees' => [ 'driver' => 'eloquent', 'model' => App\Employees::class, ], ], If your as using 2 different model for authentication do like above. If you are using the same model to authenticate based on user role give the same model for employees and user. create Route for em

Cites J. Robinson · 2017-08 · Stack Overflow · on “Laravel Blade If Statement throwing Non-Object Property Error upon Auth Check with Guard”

I'm VERY new to laravel, so I'm honestly not sure what information to provide but I'll try to the best of my ability to ask the question throughly. Lets take a look at my code: @if(Auth::guard('admin')->check() || Auth::guard('web')->check()) <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> {{ Auth::user()->name }} <span class="caret"></span> </a> {{-- Authenticated Dropdown Menu --}} <ul class="dropdown-menu" role="menu"> {{-- Admin Links --}} @if (Auth::guard('admin')->check()) <li><a href="{{ route('posts.index') }}">Manage Blog Posts</a></li> <li role="separator" class="divider"></li> @endif {{-- User Links --}} @if (Au