0

I am working on a small food website for my Uncle's shop. Webshop can have different types of Users: Admin, Customer, and, Delivery boys.

Each user has different tables in the database. I have updated also config/auth.php accordingly but still doesn't work. It throws me the error when I try to register a customer:

Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must implement interface Illuminate\Contracts\Auth\UserProvider, null given, called in /var/www/html/pizzaShop/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 125

config/auth.php

return [

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'customers',
    ],

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
        'customer' => [
            'driver' => 'session',
            'provider' => 'customers',
        ],
        'delivery_boy' => [
            'driver' => 'session',
            'provider' => 'delivery_boys',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'customers',
            'hash' => false,
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

        'admin' => [
            'driver' => 'eloquent',
            'model' => App\Admin::class,
        ],
        'customer' => [
            'driver' => 'eloquent',
            'model' => App\Customer::class,
        ],
        'delivery_boy' => [
            'driver' => 'eloquent',
            'model' => App\DeliveryBoy::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],


    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
            'throttle' => 60,
        ],
    ],

    'password_timeout' => 10800,

];

Register controller under COntroller/Auth

class RegisterController extends Controller
{
    
    use RegistersUsers;
    protected $redirectTo = RouteServiceProvider::HOME;
    public function __construct()
    {
        $this->middleware('guest');
        $this->middleware('guest:admin');
        $this->middleware('guest:customer');
        $this->middleware('guest:delivery_boy');
    }
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
    public function viewRegisterForm() {
        return View('frontend.customer.auth-view', ['authType'=>'register']);
    }
    public function registerUser(Request $request) {
        dd($request);
        return View('frontend.customer.auth-view', ['authType'=>'register']);
    }
}

Web routes for my register

Route::get('/auth/', function () {
    return view('frontend.customer.auth-view');
});
Route::group(['prefix' => 'auth'], function () {
    Route::get('register/', 'Auth\RegisterController@viewRegisterForm');
    Route::post('register/', 'RegisterController@registerUser');

    Route::get('login/', 'Auth\LoginController@viewLoginForm');
    Route::post('login/', 'LoginController@loginUser');

});
Auth::routes();

I am using my own views rather than created by Laravel UI but the routes for forms for my view are action="{{ route('login') }}" and action="{{ route('register') }}". I hope this shouldn't be a problem.

Url to navigate to register for via browser:

http://localhost:8000/auth/register

and the error gfh

I am using laravel 7 with php7.4.

Phoenix404
  • 898
  • 1
  • 14
  • 29

1 Answers1

1

You have no User Provider named admins, customers or delivery_boys, as certain guards are looking for as the 'provider'. You named them in the singular:

'providers' => [
    'users' => [...],
    'admin' => [...],
    'customer' => [...],
    'delivery_boy' => [...],
]
lagbox
  • 48,571
  • 8
  • 72
  • 83
  • Thanks for the answer but how can I overwrite the routes of laravel UI? Currently I have the route for registration is `auth/register` with post but if a user types on my host `www.example.com/register` the laravel app brings it to the `www.example.com/register` which one created by the laravel UI. – Phoenix404 Aug 30 '20 at 10:14
  • 1
    override which routes? you can not call `Auth::routes()` – lagbox Aug 30 '20 at 10:15
  • How can I modify the routes in `Auth::routes()` ? – Phoenix404 Aug 30 '20 at 10:17
  • 1
    you can't modify them, the only thing you can do is pass options to `Auth::routes()` to stop it from registering certain sets of routes ... otherwise just register the routes you want yourself and don't call `Auth::routes()` – lagbox Aug 30 '20 at 10:18