How to solve Auth guard [web] is not defined problem - laravel

I make 2 guards 1. For admin and 2. for student. Now when i click on my button to show the login form i always caught that error that Auth guard [web] is not defined.Now how i solve this.
here is my config/auth.php
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'student' => [
'driver' => 'session',
'provider' => 'student',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
'providers' => [
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
'students' => [
'driver' => 'eloquent',
'model' => App\Student::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
I am trying login the admin using admin guard.Please help me to solve that and i dont use default User.php model.

That's because you're removing web guard from the application.
Just change your default guard from web to your new guard.
'defaults' => [
'guard' => 'admins',
'passwords' => 'users',
],

Related

how to solve Laravel 6.0 error upload file

I'm trying to input some data to database
i cant input some data to database because i got that error
but i can login with multi auth in my project
and i got some error
how i can solve this error?
controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Jurusan;
use Auth;
class AdminActionsController extends Controller
{
public function addjurusan(Request $request)
{
$jurusan = new Jurusan();
$jurusan->nama_jurusan=$request->nama;
$file=$request->file('fotohimpunan');
if (!$file) {
return redirect()->route('in.jurusan')->with('alert','foto harus diisi!');
}
$file_name=$file->getClientOriginalName();
$path=public_path('/img');
$file->move($path,$file_name);
$jurusan->fotohimpunan='public/img/'.$file_name;
$jurusan->status='disable';
// dd($jurusan);
$jurusan->save();
return redirect()->route('in.jurusan');
}
}
guard
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
// Guard
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admin',
],
'admin-api' => [
'driver' => 'token',
'provider' => 'admin',
],
'panitia' => [
'driver' => 'session',
'provider' => 'panitia',
],
'panitia-api' => [
'driver' => 'token',
'provider' => 'panitia',
],
'mahasiswa' => [
'driver' => 'session',
'provider' => 'mahasiswa',
],
'mahasiswa-api' => [
'driver' => 'token',
'provider' => 'mahasiswa',
],
],
// Providers
'providers' => [
'panitia' => [
'driver' => 'eloquent',
'model' => App\Panitia::class,
],
'admin' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
'mahasiswa' => [
'driver' => 'eloquent',
'model' => App\Mahasiswa::class,
],
],
// Password
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
];
how i can solve my problems please help me
i can login with multi auth but if i try to input some data i got that error
You don't have a users provider:
'providers' => [
'panitia' => [
'driver' => 'eloquent',
'model' => App\Panitia::class,
],
'admin' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
'mahasiswa' => [
'driver' => 'eloquent',
'model' => App\Mahasiswa::class,
],
],
The web guard is set to use a provider named users:
'web' => [
'driver' => 'session',
'provider' => 'users',
],
You need to adjust that to use a provider you have registered, or add a users provider.
Are you intending to be using the web guard for which ever route you are hitting and getting the error? It is possible you intend to use a different guard completely.

The 'email' key is missing from the given credentials array

after updating my Laravel and Adldap2 to version 6.0,i'm receiving this error when i'm trying to authenticate,
**
The 'email' key is missing from the given credentials array
**
what is the reason behind that ?
i haven't changed anything in my LoginController or Auth.php or anywhere else,
my config/auth.php
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'ldap', //'eloquent',
'model' => App\User::class,
'table' => 'users',
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
];
After upgrading to Laravel 6 and adldap 6 You need to republish config files.
https://github.com/Adldap2/Adldap2-Laravel/blob/master/docs/upgrading.md

Error on multiple auth

I have tried to create multiple auth, but everytime i am getting:
Type error: Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given, called in /Users/admin/www/laravelapp/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 123
Searched in google but nothing helped. Have no idea. May be someone got this error before? my auth.php in config:
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'admin-api' => [
'driver' => 'token',
'provider' => 'admins',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admin' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
],
...
Cleared cache. But not helped. PS: i have used it before in another project but not worked in new one. :/
Oh my GOD, i found the problem. Problem: providers name was wrong :/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'admin-api' => [
'driver' => 'token',
'provider' => 'admins',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [ //<----- changed to admins like in guards
'driver' => 'eloquent',
'model' => App\Admin::class,
],
],
...
Sometimes you need just post code to stackoverflow to see your own problem :)

Laravel Multiple Auth::attempt

I have two models in my laravel v5.4 project, user and admin.
In config/auth.php i added admin to guards and providers as below :
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
],
Now in AdminController class i want to use Auth::attempt function but by default it uses the users table. I can change defaults in config/auth.php as below and it works but in this case i can not use Auth::attempt for users.
'defaults' => [
'guard' => 'admin',
'passwords' => 'users',
],
I want to set user as default but use Auth::attempt function for admin with a method like Auth::attempt('admin',[credentials]). How can i use Auth::attempt for Admin model?
You call the guard directly, like this:
Auth::guard('admin')->attempt($credentials);
Or with the helper:
auth()->guard('admin')->attempt($credentials);
Or, even shorter with the helper:
auth('admin')->attempt($credentials);

How to convert Auth::guard('web') to Auth::guard('user') in Laravel 5.3?

I have 2 guard in Laravel 5.3: web and admin.
I need to convert Auth::guard('web') to Auth::guard('user') in Laravel 5.3?
How to convert web to user?
After change in auth.php:
'defaults' => [
'guard' => 'user',
'passwords' => 'users',
],
'guards' => [
'user' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admin',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admin' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
You should open config/auth.php
There you should update web to user on guards array and defaults array also in providers and passwords array and you will have guard('user').

Resources