【发布时间】:2018-12-11 20:54:42
【问题描述】:
就我而言,我有一个用户
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('address_id')->nullable();
$table->foreign('address_id')->references('id')->on('addresses');
$table->string('first_name');
$table->string('insertion')->nullable();
$table->string('last_name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('phone_number');
$table->string('avatar')->nullable();
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});
我有一个地址
Schema::create('addresses', function (Blueprint $table) {
$table->increments('id');
$table->string('city');
$table->string('street');
$table->string('zip_code');
$table->string('state');
$table->string('house_number');
$table->timestamps();
});
是否可以在同一个 Nova 用户资源中创建新用户并为其添加地址?
我们可以在资源的字段功能中添加什么?
我需要覆盖默认的创建方法吗?或者这可以用 belongsTo 来解决吗?
目前我可以使用
morhpone
方法,但这不是我想要的。我首先必须创建一个用户,然后我可以添加一个地址。
【问题讨论】:
-
IMO,你的关系倒退了。现在,您的用户属于一个地址。通常,地址属于用户。
标签: laravel laravel-nova