mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 21:11:05 +03:30
84 lines
2.2 KiB
PHP
84 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Constants\StatusTypeEnum;
|
|
use App\Services\Media\HasMediaTrait;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Spatie\Image\Exceptions\InvalidManipulation;
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
|
|
|
class Item extends Model implements HasMedia
|
|
{
|
|
use HasMediaTrait;
|
|
|
|
public $fillable = ['name', 'size', 'unique_id', 'specific', 'note', 'user_id', 'udi', 'status', 'repair', 'package_id', 'creator_id'];
|
|
|
|
public function scopeIsNotRepaired($query)
|
|
{
|
|
return $query->where('repair', 0);
|
|
}
|
|
|
|
public function package()
|
|
{
|
|
return $this->belongsTo('App\Package');
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo('App\User');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo('App\User', "creator_id");
|
|
}
|
|
|
|
public function transfersAll()
|
|
{
|
|
return $this->morphMany('App\Transfer', "transferable")->orderBy("id", "desc");
|
|
}
|
|
|
|
public function transfers()
|
|
{
|
|
return $this->morphMany('App\Transfer', "transferable")->where("status", StatusTypeEnum::APPROVED)->orderBy("id", "desc");
|
|
}
|
|
|
|
public function latestTransfer()
|
|
{
|
|
return $this->morphOne('App\Transfer', "transferable")->where("status", StatusTypeEnum::APPROVED)->orderBy("id", "desc")->latest();
|
|
}
|
|
|
|
public function transferActive()
|
|
{
|
|
return $this->morphMany('App\Transfer', "transferable")->where("status", StatusTypeEnum::APPROVED)->whereNull("to_date")->orderBy("id", "desc");
|
|
}
|
|
|
|
public function registerMediaCollections(): void
|
|
{
|
|
$this->addMediaCollection('files')
|
|
->useFallbackUrl('/files/default_pastry.jpg')
|
|
->useFallbackPath(public_path('/files/default_pastry.jpg'));
|
|
}
|
|
|
|
/**
|
|
* @throws InvalidManipulation
|
|
*/
|
|
public function registerMediaConversions(Media $media = null): void
|
|
{
|
|
$this->addMediaConversion('thumbnail')
|
|
->width(480)
|
|
->height(640)
|
|
->nonQueued()
|
|
->performOnCollections('files');
|
|
}
|
|
|
|
protected static function getValidCollections(): array
|
|
{
|
|
return [
|
|
'files'
|
|
];
|
|
}
|
|
}
|