Я работаю над базой данных Eloquent Relationship One to one, но после написания кода я получаю сообщение об ошибке: SQLSTATE [42S22]: Столбец не найден: 1054 Неизвестный столбец 'posts.deleted_at' in 'where clause' (SQL: select * from `posts` where `posts`.`user_id` = 1 and `posts`.`user_id` is not null and `posts`.`deleted_at` is null limit 1
) этот код предназначен для таблицы сообщений, где я связал user_id
Перенос таблицы сообщений
class CreatePostTable extends Migration
{
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('title');
$table->text('body');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('posts');
}
}
это таблица пользователей, в которой я должен связать сообщение
Перенос модели пользователя
class CreateUsersTable extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('users');
}
}
Пользователь. php код
public function post(){
return $this->hasOne('App\Post'); //select * from post where user_id = 1
}
и это маршрут:
Routes \ web. php
Route::get('user/{id}/post', function ($id) {
return User::find($id)->post;
});