gpt4 book ai didi

mysql - 在 Laravel 5.6 中注册时出错

转载 作者:行者123 更新时间:2023-11-29 02:42:05 26 4
gpt4 key购买 nike

我想在应用程序中注册时遇到错误。我有一个表寄存器,我删除了它。当我想注册时,所有数据都转到了那个表。现在我希望他们转到用户表,我有以下功能和模型。但是当我提交要注册的信息时,会弹出此错误

QLSTATE[42S02]: Base table or view not found: 1146 Table '24gardi.registers' doesn't exist (SQL: select count(*) as aggregate from `registers` where `username` = amirhosseingheibi@gmail.com)

这是 Controller :

public function ShowRegisterForm()
{
$title = "ثبت نام";
return view('register')->with('title', $title);
}

public function register(Request $request)
{
$this->validation2($request);
$register = User::create([
'username' => $request->input('username'),
'password' => bcrypt($request->input('username')),
'register_type' => $request->input('username'),
'first_name' => $request->input('username'),
'last_name' => $request->input('username'),
'gender' => $request->input('username'),
'email' => $request->input('username'),
'mobile' => $request->input('username'),
'national_id' => $request->input('username'),
'personnel_pic' => $request->input('username'),
'contract_pic' => $request->input('username'),
'national_id_pic' => $request->input('username'),
'profile_pic' => $request->input('username')
]);
if ($register) {
return redirect('/')->with('success', 'ثبت نام با موفقیت انجام شد.');
}
return redirect('/register')->with('errors', 'ثبت نام با موفقیت انجام نشد.');
}

public function validation2($request)
{
return $this->validate($request, [
'username' => 'required|unique:registers|max:255',
'password' => 'required|max:255',
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'national_id' => 'required|unique:registers|max:10',
'gender' => 'required|max:5',
'email' => 'required|email|unique:registers|max:255',
'mobile' => 'required|max:13'
]);
}

这是路由(命名路由是在 View 中使用的路由):

Route::Get('/register', 'UsersController@ShowRegisterForm');
Route::Post('/register', 'UsersController@register')->name('custom.register');

这是模型(是的,我在名为 UsersController 的 Controller 中添加了 use App\User(用户表的模型)):

protected $table = 'users';

protected $fillable = [
'register_type',
'username',
'password',
'first_name',
'last_name',
'national_id',
'gender',
'mobile',
'email',
'personnel_pic',
'national_id_pic',
'contract_pic',
'profile_pic',
'score'
];

public function tours ()
{
return $this->belongsToMany('App\Tour');
}

public function comments ()
{
return $this->hasMany('App\Comment');
}

public function suggestions ()
{
return $this->belongsToMany('App\Suggestion');
}


/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'remember_token',
];

我想说的是,我不明白为什么会弹出错误。如果有人知道错误是什么,请帮助我。

最佳答案

您在 Validations() 中引用了错误的表

 public function validation2($request)
{
return $this->validate($request, [
'username' => 'required|unique:users|max:255',
'password' => 'required|max:255',
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'national_id' => 'required|unique:users|max:10',
'gender' => 'required|max:5',
'email' => 'required|email|unique:users|max:255',
'mobile' => 'required|max:13'
]);
}

阅读有关验证的更多信息 here

关于mysql - 在 Laravel 5.6 中注册时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49295875/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com