| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
-
- namespace App\Models;
-
- use Illuminate\Database\Eloquent\Attributes\Fillable;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Support\Facades\Storage;
-
- /**
- * A photo the merchant uploaded for the store's design, such as a hero banner.
- * The file lives on the "public" storage disk. The design points to it as "upload:{id}".
- *
- * @property int $id
- * @property int $store_id
- * @property string $path
- */
- #[Fillable(['path'])]
- class StoreImage extends Model
- {
- protected static function booted(): void
- {
- static::deleted(function (StoreImage $image): void {
- Storage::disk('public')->delete($image->path);
- });
- }
-
- /**
- * @return BelongsTo<Store, $this>
- */
- public function store(): BelongsTo
- {
- return $this->belongsTo(Store::class);
- }
-
- /**
- * Address of the photo, without the site name, so it works on any local port.
- */
- public function url(): string
- {
- return '/storage/'.$this->path;
- }
-
- public function reference(): string
- {
- return 'upload:'.$this->id;
- }
- }
|