| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?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\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();
- }
- protected function image(): Attribute
- {
- return Attribute::make(
- get: fn (): string => (string) ($this->imageFile?->thumbnail_link ?? ''),
- );
- }
- }
|