我正在为我叔叔的商店开发一个小型食品网站。网上商店可以有不同类型的用户:管理员、客户和送货员。
每个用户在数据库中都有不同的表。我也相应地更新了 config/auth.php 但仍然无法正常工作。当我尝试注册客户时,它会抛出错误:
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
配置/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,
];
在 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']);
}
}
我的注册网络路线
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();
我使用的是我自己的视图,而不是由 Laravel UI 创建的,但我的视图的表单路由是action="{{ route('login') }}"
和action="{{ route('register') }}"
. 我希望这应该不是问题。
通过浏览器导航到注册的 URL:
http://localhost:8000/auth/register
我正在使用带有 php7.4 的 laravel 7。