AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ProductImage.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Attributes\Fillable;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Illuminate\Support\Facades\Storage;
  7. /**
  8. * One photo of a product. The file lives on the "public" storage disk.
  9. *
  10. * @property int $id
  11. * @property int $store_id
  12. * @property int $product_id
  13. * @property string $path
  14. * @property int $position
  15. */
  16. #[Fillable(['store_id', 'path', 'position'])]
  17. class ProductImage extends Model
  18. {
  19. protected static function booted(): void
  20. {
  21. static::deleted(function (ProductImage $image): void {
  22. Storage::disk('public')->delete($image->path);
  23. });
  24. }
  25. /**
  26. * @return BelongsTo<Product, $this>
  27. */
  28. public function product(): BelongsTo
  29. {
  30. return $this->belongsTo(Product::class);
  31. }
  32. /**
  33. * Address of the photo, without the site name, so it works on any local port.
  34. */
  35. public function url(): string
  36. {
  37. return '/storage/'.$this->path;
  38. }
  39. }