Всем привет. Вот мои миграции news и images. Код (Text): Schema::create('news', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->integer('s_img_id')->unsigned()->index()->nullable(); $table->integer('f_img_id')->unsigned()->index()->nullable(); $table->foreign('s_img_id')->references('id')->on('images'); $table->foreign('f_img_id')->references('id')->on('images'); $table->timestamps(); }); Код (Text): Schema::create('images', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->timestamps(); }); Как выбрать картинку новости? в модели news описал метод image: Код (Text): public function image() { return $this->hasOne('App\Image'); } Ошибка: Код (Text): Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'images.s_img_id' in 'where clause' (SQL: select * from `images` where `images`.`s_img_id` = 1 and `images`.`s_img_id` is not null limit 1)'
иди еще доку почитай на предмет какие параметры можно указывать в методе hasOne, если названия полей не совпадают с теми, которые сопостовляются по умолчанию
Терминал незачем перезапускать. Вот тинкер надо, потому что если консольный скрипт один раз подгрузил файл с классом, он его не будет перечитывать заново.