Доброе утро, я пытаюсь сделать модели данных для приложения рабочих семинара. Проблема возникает с направляющими и изображениями моделей данных. Каждый гид имеет свое собственное изображение, и каждое изображение принадлежит гиду. Когда я пытаюсь запустить миграцию и Laravel выдает SQLSTATE, и я не нахожу ошибку, поэтому я был бы признателен за вашу помощь.
Миграция направляющих:
Schema::create('guides', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->text('topic')->nullable();
$table->string('author')->nullable();
$table->year('year')->nullable();
$table->text('goal')->nullable();
$table->text('description')->nullable();
$table->smallInteger('assistants_quantity')->nullable();
$table->smallInteger('duration_hours')->nullable();
$table->string('methodology')->nullable();
$table->bigInteger('image_id')->unsigned();
$table->foreign('image_id')->references('id')->on('images');
$table->timestamps();
$table->softDeletes();
});
модель направляющих:
class Guide extends Model
{
protected $table = 'guides';
public $timestamps = true;
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $fillable = ['title', 'topic', 'author', 'year', 'goal', 'description', 'assistants_quantity', 'duration_hours', 'methodology'];
protected $visible = ['title','topic', 'author', 'year', 'goal', 'description', 'assistants_quantity', 'duration_hours', 'methodology'];
public function materials()
{
return $this -> belongsToMany(Material::class);
}
public function images()
{
return $this -> belongsTo(Image::class);
}
static function search($keyword)
{
$result = Guide::where('title', 'LIKE', '%' . $keyword . '%')->get();
return $result;
}
}
Миграция изображений:
Schema::create('images', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('image');
$table->timestamps();
});
Модель изображений:
class Image extends Model
{
protected $fillable = ['image'];
public function images()
{
return $this -> belongsTo(Guide::class);
}
}
Обновление: php Ремесленник: статусное изображение