我是新来的,我正在看youtube的播放列表来构建我的第一个项目……现在我正在尝试实现一个仅用于inv的系统,这样注册表单看起来就像
username:
inv code:
password:我已经创建了一个迁移,它具有
user_id - this is user id of the user who created the invite
code - the code which will get validated at time of registration and then deleted
{timestamps}因此,im遇到的问题是:如何验证用户输入的invite存在于表"inv_codes“中,并与列"code”匹配,然后在完成注册后将其删除
下面是一个最小的可重现的例子
lass RegisterController extends Controller
{
public function __construct()
{
$this->middleware(['guest']);
}
public function index()
{
return view('auth.register');
}
public function submit(Request $request)
{
$this->validate($request, [
'username' => 'required|max:6',
'password' => 'required',
]);
User::create([
'username' => $request->username,
'password' => Hash::make($request->password),
]);
auth()->attempt($request->only('username', 'password'));
return redirect()->route('dashboard');
}
}发布于 2021-01-25 03:47:33
假设您在users和inv_codes表中都有code列。现在,在注册过程中,您可以使用验证。如下所示:
$request->validate([
'code' => 'required|exists:inv_codes,code',
// ... rest of registration fields
]);然后,您可以通过如下方式删除inv_codes表中的该行:您可以在:https://laravel.com/docs/8.x/validation#quick-writing-the-validation-logic上阅读更多信息
DB::table('inv_codes')->where('code', $request->code)->delete();有关更多信息,请访问:https://laravel.com/docs/8.x/queries#delete-statements
https://stackoverflow.com/questions/65875015
复制相似问题