基本上,我想要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和[database migrations][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 —如何从1个表单发送2个查询?例如:通过电子邮件发送到一个表,将用户名发送到另一个表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56807434/