mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 21:21:08 +03:30
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
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 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 transfers()
|
|
{
|
|
return $this->morphMany( 'App\Transfer' , "transferable" )->where( "status" , "approved" );
|
|
}
|
|
|
|
public function transferActive()
|
|
{
|
|
return $this->morphMany( 'App\Transfer' , "transferable" )->where( "status" , "approved" )->whereNull( "to_date" );
|
|
}
|
|
|
|
public function registerMediaCollections(): void
|
|
{
|
|
$this->addMediaCollection( 'main_image' )
|
|
->useFallbackUrl( config( 'media-library.wm-cdn' ) . '/images/placeholder/blog-placeholder.jpg' )
|
|
->useFallbackPath( public_path( '/images/placeholder/blog-placeholder.jpg' ) )
|
|
->singleFile();
|
|
}
|
|
|
|
public function registerMediaConversions( Media $media = null )
|
|
{
|
|
$crop = $media->getCustomProperty( 'crop' );
|
|
$conversion = $this->addMediaConversion( 'thumbnail' );
|
|
$conversion = ! $crop ? $conversion : $conversion->manualCrop( $crop[ 'width' ] , $crop[ 'height' ] , $crop[ 'left' ] , $crop[ 'top' ] );
|
|
$conversion->nonQueued()
|
|
->performOnCollections( 'main_image' );
|
|
|
|
$this->addMediaConversion( 'thumbnail' )
|
|
->width( 400 )
|
|
->nonQueued()
|
|
->performOnCollections( 'images' );
|
|
}
|
|
}
|