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

标签 mysql laravel

基本上,我想要 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/

相关文章:

mysql - SQL 数据库 : use one table with 3, 5M 条目或条目较少的许多表?

mysql - 如何在一个查询中链接 SQL 选择结果?

mysql - 拉拉维尔 |即使使用 find ,查询也会返回所有记录的集合

php - 数据库中的 Laravel 订单项

laravel - 从缓存laravel中的数组获取对象值

php - 如何在不等待一个结束执行的情况下执行多个 artisan 命令?

java - 如何在play framework 2.0中执行sql文件?

php - PHP 中的 MySQL 错误,但不是通过 CLI

mysql - 查询mysql数据库时出错

php - Laravel Mailer 不发送或重定向