4 回答
TA贡献1893条经验 获得超10个赞
我有同样的错误,它是由于错误的验证角色而发生的。
我收到了这个错误:
{
"message": "Database connection [users] not configured.",
"exception": "InvalidArgumentException", ...
}
再次检查您的验证规则,尤其是在 [unique] 规则上。
我的错误代码:
$rules = [
'username' => 'required|min:8|unique:users.username,'.$request->input('user-id')
];
正确的:
$rules = [
'username' => 'required|min:8|unique:users,username,'.$request->input('user-id')
];
您在“Auth/RegisterController.php”中有同样的问题:替换这个:
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:20'],
'surname' => ['required', 'string', 'max:30'],
'age' => ['required', 'integer', 'max:100'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users.email'],
'password' => ['required', 'string', 'min:6'],
'confirm' => ['required', 'string', 'same:password']
]);
}
有了这个 :
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:20'],
'surname' => ['required', 'string', 'max:30'],
'age' => ['required', 'integer', 'max:100'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email'],
'password' => ['required', 'string', 'min:6'],
'confirm' => ['required', 'string', 'same:password']
]);
}
TA贡献1876条经验 获得超7个赞
我在 Laravel 8.x 上遇到了同样的错误,为了解决您的问题,您必须将电子邮件输入的验证规则从更改unique:users.email为unique:users,email:
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:20'],
'surname' => ['required', 'string', 'max:30'],
'age' => ['required', 'integer', 'max:100'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email'],
'password' => ['required', 'string', 'min:6'],
'confirm' => ['required', 'string', 'same:password']
]);
}
TA贡献1871条经验 获得超13个赞
首先运行php artisan config:cache & php artisan cache:clear并重试。如果问题仍然存在,您可以在用户模型中手动指定数据库连接:
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
# database connection
protected $connection = 'mysql';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'surname', 'age', 'email', 'password', 'code', 'ban', 'ban_reason', 'created_at', 'image', 'role', 'confirmed'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'code', 'confirmed'
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
通常这不是必需的,因为您的应用程序mysql用作默认连接,尽管我不知道您的环境。问题可能在任何地方。希望这可以帮助。
- 4 回答
- 0 关注
- 109 浏览
添加回答
举报