mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-12 16:21:06 +03:30
fix: change models namespace
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Constants\StatusTypeEnum;
|
||||
use App\Services\Media\HasMediaTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
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(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Package::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, "creator_id");
|
||||
}
|
||||
|
||||
public function transfersAll(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Transfer::class, "transferable")->orderBy("id", "desc");
|
||||
}
|
||||
|
||||
public function transfers(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Transfer::class, "transferable")
|
||||
->where("status", StatusTypeEnum::APPROVED)
|
||||
->orderBy("id", "desc");
|
||||
}
|
||||
|
||||
public function latestTransfer(): MorphOne
|
||||
{
|
||||
return $this->morphOne(Transfer::class, "transferable")
|
||||
->where("status", StatusTypeEnum::APPROVED)
|
||||
->orderBy("id", "desc")->latest();
|
||||
}
|
||||
|
||||
public function transferActive(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Transfer::class, "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'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user