Auth guard [:superAdmin] is not defined [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
am creating a custom guard for the admin and am getting the error "auth guard is not defined"
i have tried "php artisan config:clear and php artisan config cache" but still the error. i wonder what i am doing wrong.
Here is my auth config
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
'SuperAdmin' => [
'driver' => 'session',
'provider' => 'admins',
],
'superAdmin-api' => [
'driver' => 'token',
'provider' => 'admins',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];
AdminController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AdminController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth::superAdmin');
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('admin');
}
}
AdminLoginController
<?php
namespace App\Http\Controllers\auth;
use auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class AdminLoginController extends Controller
{
public function __construct()
{
$this->middleware('guest:superAdmin', ['Except' => ['logout']]);
}
public function showLoginForm()
{
return view('auth.adminLogin');
}
public function login(Request $request)
{
// validate the input from the admin
$this->validate($request,
['email' => 'required|email',
'password' => 'required|min:6'
]);
// attempt admin to log in
if(auth::guard('superAdmin')->attempt(['email'=>$request->email, 'password'=>$request->password], $request->get('remember')))
{
return redirect()->intended(route('admin.dashboard'));
}
//if unsucessfull take them back to the login page
return redirect()->withInput($reuest->only('email', 'remember'));
}
}

Your guard is SuperAdmin, not superAdmin

Related

Method Illuminate\Auth\SessionGuard::admin does not exist

Hello, I am facing the titled error when I try to update password. The problem I'm facing in laravel 8 framework. In case of update password I need to catch the old hashed password that is saved in the database. So, I tried in belows way, but facing this error.
auth.php below
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that each reset token will be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];
Admin Controller method
public function UpdatePassword(Request $request)
{
$request->validate([
'old_password' => 'required',
'new_password' => 'required|confirmed',
]);
if(!Hash::check($request->old_password, auth()->admin()->password)){
return back()->with("error", "Old Password Doesn't match!");
}
// $hashedPassword = Auth::Admin()->password;
// if(Hash::check($request->old_password, $hashedPassword)){
// $admin = Admin::find(Auth::id());
// $admin->password = Hash::make($request->new_password);
// $admin->save();
// Auth::Logout();
// return redirect('admin')->with('status', 'Password Changed Successfully!');
// }
// else{
// return redirect()->back()->with('error', 'Something Wrong!');
// }
// return redirect()->back()->with('status', 'Password Changed Successfully!');
}
The method admin() doesnt exist in the Auth classes. Use the guard admin and the method user()
if(!Hash::check($request->old_password, auth('admin')->user()->password)){
auth('admin')->user()
//will return an instance of the model of the "admin" guard. in this case App\Models\Admin::class

The problem with guards in Laravel (Auth::login($user) function does not work)

When creating multiatorization in laravel, I edited the file config/auth.php as follows:
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'client',
'passwords' => 'clients',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session"
|
*/
'guards' => [
'client' => [
'driver' => 'session',
'provider' => 'clients',
],
'master' => [
'driver' => 'session',
'provider' => 'masters',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'clients' => [
'driver' => 'eloquent',
'model' => App\Models\Client::class,
],
'masters' => [
'driver' => 'eloquent',
'model' => App\Models\Master::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that each reset token will be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'clients' => [
'provider' => 'clients',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'masters' => [
'provider' => 'masters',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];
client - designed for client authentication
master - designed for authentication of masters
When following the route to register the master, my Auth::login($user) method does not authenticate the him. And when calling the dd(Auth::user()) function, it returns null.
As I later found out, only the default guard (i.e. the client) is triggered for me.
How do I make it so that guard master is triggered for authentication of masters, and guard client is triggered for authentication of clients
Additionally:
my routes:
Route::middleware('guest')->group(function () {
// client:register
Route::get('/client/register', [ClientRegisterController::class, 'create'])
Route::post('/client/register', [ClientRegisterController::class, 'store'])
// master:register
Route::get('/master/register', [MasterRegisterController::class, 'create'])
Route::post('/master/register', [MasterRegisterController::class, 'store'])
});
my MasterRegisterController:
class MasterRegisterController extends Controller
{
/**
* Display the registration view.
*
* #return \Illuminate\View\View
*/
public function create()
{
return view('auth.masterRegister');
}
/**
* Handle an incoming registration request.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\RedirectResponse
*
* #throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request)
{
$request->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:masters'],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);
$user = Master::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
// add role to master
$user->attachRole('master');
event(new Registered($user));
Auth::login($user);
return redirect(url('/master/dashboard'));
}
}

Laravel 8 Multi-authentication Using Guards Rest Password PROBLEM

I am trying to make a Laravel App with multi-authentication using guards.
Github: Repository
I created a Fresh Laravel 8 App and added admin guard and now I am able to login and logout in both admin and user modes.
This Picture Shows the details of what I did you can skip and just read Admin reset password section below
config/auth.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 30,
'throttle' => 30,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];
Admin Reset Password Section
I added the flowing functions to PasswordResetLinkController and NewPasswordController for admin:
/**
* Get the guard to be used during authentication.
*
* #return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard('admin');
}
/**
* Returns the password broker for admins
*
* #return broker
*/
protected function broker()
{
return Password::broker('admins');
}
And then I went to /admin/forget-password route and submitted the admin email but I got the following error: We can't find a user with that email address.
After checking I found that in the function store of the PasswordResetLinkController it is attempting to find an admin email in the users table/model. Here is function store:
/**
* Handle an incoming password reset link request.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\RedirectResponse
*
* #throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request)
{
$request->validate([
'email' => 'required|email',
]);
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$status = Password::sendResetLink(
$request->only('email')
);
return $status == Password::RESET_LINK_SENT
? back()->with('status', __($status))
: back()->withInput($request->only('email'))
->withErrors(['email' => __($status)]);
}
How can I force classes PasswordResetLinkController and NewPasswordController to use guard() and broker() functions I added to them?
Sorry for the long explanation I tried to search for this question on multiple platforms they are only using the roles approach to do it, if I didn't explain thoroughly some might not understand what I am trying to do
Since you are using Laravel Breeze, replace this line of code in the store() method of the PasswordResetLinkController.php class.
$status = Password::sendResetLink($request->only('email'));
With the following line.
Password::broker('admins')->sendResetLink($request->only('email'))
Override the broker function :-
in your PasswordResetLinkController.php, add the following function;
/**
* Get the broker to be used during password reset.
*
* #return \Illuminate\Contracts\Auth\PasswordBroker
*/
public function broker(): \Illuminate\Contracts\Auth\PasswordBroker
{
return Password::broker('admins');
}
Now update the store function in PasswordResetLink.php by replacing
$status = Password::sendResetLink(
$request->only('email')
);
to
$status = $this->broker()->sendResetLink(
$request->only('email')
);
That should do it!
In config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'tenant' => [
'driver' => 'session',
'provider' => 'tenant',
],
///
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'tenant' => [
'driver' => 'eloquent',
'model' => App\Models\Tenant\User::class,
],
],
///
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'tenant' => [
'provider' => 'tenant',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
In the config/fortify.php file
'passwords' => ['users','tenant'],
extend the PasswordBrokerManager class and override the broker method like
public function broker($name = null)
{
$name = $name ?: $this->getDefaultDriver();
if (Tenancy::getTenant()) {
return $this->brokers[$name[1]] ?? ($this->brokers[$name[1]] = $this->resolve($name[1]));
}
else
return $this->brokers[$name[0]] ?? ($this->brokers[$name[0]] = $this->resolve($name[0]));
}
In my case, I check for tenant environment. You can customize your by your needless, in your case for admin or user guard

How To Properly Setup Multiple Authentication Token using JWT Laravel

I have module where I need to setup multiple authentication api login for user account and admin account. I used laravel as my backend and JWT for my token. after all I setting up all requirements, I have encounter error after I tried to access the login api of admin in the postman just see the attached image on the below. http://localhost:8000/admin/v1/login it says that NotFoundHttpExpception. same thing accessing the login api of user http://localhost:8000/user/v1/login
"exception": "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",
Whole Image Error Postman:
Here is the setup I made:
Auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'api',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'user' => [
'driver' => 'jwt',
'provider' => 'users',
'hash' => false,
],
'admin' => [
'driver' => 'jwt',
'provider' => 'admins',
'hash' => false,
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];
Api.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::group([
'prefix' => 'v1'
], function () {
Route::post('login','App\Http\Controllers\AdminAuthController#login');
Route::post('logout', 'App\Http\Controllers\AdminAuthController#logout');
Route::post('refresh', 'App\Http\Controllers\AdminAuthController#refresh');
Route::post('me', 'App\Http\Controllers\AdminAuthController#me');
});
Route::group([
'prefix' => 'v1'
], function () {
Route::post('login','App\Http\Controllers\AuthController#login');
Route::post('logout', 'App\Http\Controllers\AuthController#logout');
Route::post('refresh', 'App\Http\Controllers\AuthController#refresh');
Route::post('me', 'App\Http\Controllers\AuthController#me');
});

Laravel broadcasting auth working or for web guard or for custom guard

In project I have two auth guards, web (users, by default), and my custom (teachers). I have noticed, that teachers can't authorize in broadcast. After adding middleware in Broadcast::routes(['middleware' => ['web', 'auth:teacher']]), the teachers are authorizing successfully, but the users are redirecting to login page.
So I have following problem:
Having Broadcast::routes(); code, the broadcast working fine only
for users guard, for teachers it returns 403 forbidden error.
Having Broadcast::routes(['middleware' => ['web', 'auth:teacher']]); code, the broadcast working only for teachers
guard, for users is redirecting to auth, login, then user page.
config/auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'teacher' => [
'driver' => 'session',
'provider' => 'teacher',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'teacher' => [
'driver' => 'eloquent',
'model' => App\Teacher::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];
app\Providers\BroadcastServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
Broadcast::routes(['middleware' => ['web', 'auth:teacher']]);
require base_path('routes/channels.php');
}
}
This is coming late, However, You should try this if you have not Broadcast::routes(['middleware' => ['auth:web', 'auth:teacher']]);
Broadcast::routes() works for student because the default 'auth:web' guard of the authentication middleware was used and when you added for the teacher you specified wrong 'web', instead of 'auth:web'.
Trying using
Broadcast::routes(['middleware' => ['auth:web', 'auth:teacher']]); or
Broadcast::routes(['middleware' => ['auth:web,teacher']]);

Categories