Answer the question
In order to leave comments, you need to log in
How to make a one-to-one connection?
Hello, tell me please, I have two models:
$table->unsignedBigInteger('image_id')->nullable();
$table->foreign('image_id')->references('id')->on('images'); //id картинки
class Category extends Model
{
public function image() //Вернёт картинку категории
{
return $this->hasOne('App\Models\Admin\Image');
}
}
class Image extends Model
{
public function category() //Получить категорию
{
return $this->belongsTo('App\Models\Admin\Category');
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question