php artisan make:model -m Image
public function up(): void
{
Schema::create('images', function (Blueprint $table) {
$table->id();
$table->string('path')->default('default.jpg');
$table->foreignId('post_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
}
class Post extends Model
{
use HasFactory;
public function image()
{
return $this->hasOne(Image::class);
}
}
<img src="{{ $posts->image->path }}" alt="{{ $posts->image->path }}">