mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 20:21:05 +03:30
80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Constants\StatusTypeEnum;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Spatie\MediaLibrary\HasMedia\HasMedia;
|
|
use App\Services\Media\HasMediaTrait;
|
|
use Spatie\MediaLibrary\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'));
|
|
}
|
|
|
|
public function registerMediaConversions( Media $media = null )
|
|
{
|
|
$this->addMediaConversion('thumbnail')
|
|
->width(480)
|
|
->height(640)
|
|
->nonQueued()
|
|
->performOnCollections('files');
|
|
}
|
|
|
|
protected static function getValidCollections(): array
|
|
{
|
|
return [
|
|
'files'
|
|
];
|
|
}
|
|
}
|