У меня есть пользовательская модель, связанная с моделью конечного пользователя с отношением hasOne.Я хочу сохранить входные данные поля формы в пользовательской и конечной модели за один раз.вот мой код;
$user = new User();
$user->first_name = $request->first_name;
$user->last_name = $request->last_name;
$user->phone_number = $request->phone_number;
$user->email = $request->email;
$user->password = $request->password;
$user->enduser->username = $request->username;
$user->save();
return user;
мои отношения
Class User extends Authenticable
{
public function enduser()
{
return $this->hasOne('App\Enduser');
}
}
моя миграция для пользователей, таким образом,
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->string('phone_number');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->enum('roles',['admin', 'enduser', 'organization', 'radio', 'employee'])->nullable();
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
, а для конечного пользователя, таким образом,
public function up()
{
Schema::create('endusers', function (Blueprint $table) {
$table->increments('id');
$table->text('address')->nullable();
$table->string('lga')->nullable();
$table->string('city')->nullable();
$table->string('state')->nullable();
$table->string('username');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('endusers');
}
Я получаю сообщение об ошибке «неизвестный столбец« имя пользователя »в предложении« где ».Как я могу сохранить такие отношения?