| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- declare(strict_types=1);
- namespace App\Models;
- use Database\Factories\CommonCatalogItemFactory;
- use Illuminate\Database\Eloquent\Casts\Attribute;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\BelongsToMany;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Database\Eloquent\Relations\HasOne;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class CommonCatalogItem extends Model
- {
- /** @use HasFactory<CommonCatalogItemFactory> */
- use HasFactory;
- use SoftDeletes;
- public const DEFAULT_SORT_BY = 'article';
- protected $fillable = [
- 'image_file_id',
- 'article',
- 'calculator_name',
- 'kind',
- 'dimensions',
- 'fall_height',
- 'additional_info',
- 'dimension_unit',
- 'weight',
- 'volume',
- 'places',
- 'composition',
- 'age_group',
- 'max_users',
- 'unit',
- 'series',
- 'trademark',
- 'note',
- ];
- protected $appends = ['image'];
- protected function casts(): array
- {
- return [
- 'fall_height' => 'decimal:3',
- 'weight' => 'decimal:3',
- 'volume' => 'decimal:3',
- 'places' => 'integer',
- 'max_users' => 'integer',
- ];
- }
- public function imageFile(): BelongsTo
- {
- return $this->belongsTo(File::class, 'image_file_id');
- }
- public function documents(): BelongsToMany
- {
- return $this->belongsToMany(
- File::class,
- 'common_catalog_item_documents',
- )->withTimestamps();
- }
- public function stockOrders(): HasMany
- {
- return $this->hasMany(StockOrder::class);
- }
- public function latestStockOrder(): HasOne
- {
- return $this->hasOne(StockOrder::class)->latestOfMany();
- }
- public function stockReservations(): HasMany
- {
- return $this->hasMany(StockReservation::class);
- }
- public function stockMovements(): HasMany
- {
- return $this->hasMany(StockMovement::class);
- }
- protected function image(): Attribute
- {
- return Attribute::make(
- get: fn (): string => (string) ($this->imageFile?->thumbnail_link ?? ''),
- );
- }
- }
|