gpt4 book ai didi

mysql - Laravel make :auth — How do I send 2 queries from 1 form? 例如:电子邮件到一张表,用户名发送到另一张表

转载 作者:行者123 更新时间:2023-11-29 15:50:11 25 4
gpt4 key购买 nike

基本上,我想要 2 个表,一个命名帐户,另一个命名字符。例如,让我创建一些虚构的数据以使这变得更容易。

(account_id自动递增)
该人将填写此注册表:

Account Name: Johnny
Character Name: John_Doe
Email: john_doe@gmail.com
Password: ********
Confirm Password: ********

所以我想做的是:
* 将“account_id”发送到两个表(帐户和字符
* 发送“账户名”、“邮箱”、“密码”到账户
* 将“character_name”发送给角色

我是 Laravel 新手,所以我真的不知道从哪里开始,这有什么关系吗?
/database/migrations/2014_10_12_000000_create_users_table.php

public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('account_name');
$table->string('character_name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
});
}

最好的情况是表格看起来像这样。

accounts [  
'account_id' => 1
'username' => Johnny
'email' => john_doe@gmail.com
'password' => ********
]

characters [
'account_id' => 1
'character_name' => John_Doe
]

最佳答案

阅读 eloquent models 上的文档和[数据库迁移][2]

快速指南是:

$ php artisan make:migrate create_characters_table

然后在database\migrations\xxxxxxxxx_create_characters_table.php...

    $table->bigInteger('account_id')->unsigned(); // Laravel's default primary keys are unsigned big integers. So foreign keys must have the same datatype.
$table->string('character_name');

然后在 Controller 方法中就很简单:

use App\Character;

public function store(Request $request)
{
$newCharacter = Character::create([
'account_id' => $request->input('account_id'),
'character_name' => $request->input('character_name')
]);
}

关于mysql - Laravel make :auth — How do I send 2 queries from 1 form? 例如:电子邮件到一张表,用户名发送到另一张表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56807434/

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