Файловый менеджер - Редактировать - /home/clickysoft/public_html/assets.clickysoft.net/app/Models/Asset.php
Назад
<?php namespace App\Models; use App\Models\Scopes\UserOrganization; use Carbon\Carbon; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; class Asset extends Model implements HasMedia { use InteractsWithMedia, HasFactory; public $table = 'assets'; protected $appends = [ 'asset_image', 'asset_document', ]; protected $dates = [ 'asset_expiration_date', 'next_audit_date', 'purchase_date', 'eol_date', 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'asset_name', 'description', 'asset_status_id', 'category_id', 'manufacturer_id', 'supplier_id', 'company_id', 'branch_id', 'qty', 'purchase_cost', 'assignable', 'maintainable', 'currency_id', 'notes', 'asset_expiration_date', 'next_audit_date', 'purchase_date', 'eol_date', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function registerMediaCollections(): void { $this->addMediaCollection('asset_document')->singleFile(); } public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 100, 100)->nonQueued(); $this->addMediaConversion('preview')->fit('crop', 200, 200)->nonQueued(); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function asset_status() { return $this->belongsTo(Status::class, 'asset_status_id'); } public function category() { return $this->belongsTo(Category::class, 'category_id'); } public function manufacturer() { return $this->belongsTo(Manufacturer::class, 'manufacturer_id'); } public function supplier() { return $this->belongsTo(Supplier::class, 'supplier_id'); } public function company() { return $this->belongsTo(Company::class, 'company_id'); } public function branch() { return $this->belongsTo(Branch::class, 'branch_id'); } public function currency() { return $this->belongsTo(Currency::class, 'currency_id'); } public function getAssetImageAttribute() { $file = $this->getMedia('asset_image')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } public function getAssetDocumentUrlAttribute() { return $this->getFirstMediaUrl('asset_document'); } public function getAssetDocumentAttribute() { return $this->getMedia('asset_image')->last(); } public function getAssetExpirationDateAttribute($value) { return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null; } public function getAssetExpirationDateFormattedAttribute($value) { return $this->asset_expiration_date ? Carbon::parse($this->asset_expiration_date)->format("d M, Y") : ""; } public function setAssetExpirationDateAttribute($value) { $this->attributes['asset_expiration_date'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null; } public function getNextAuditDateAttribute($value) { return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null; } public function setNextAuditDateAttribute($value) { $this->attributes['next_audit_date'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null; } public function getNextAuditDateFormattedAttribute($value) { return $this->next_audit_date ? Carbon::parse($this->next_audit_date)->format("d M, Y") : ""; } public function getPurchaseDateAttribute($value) { return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null; } public function setPurchaseDateAttribute($value) { $this->attributes['purchase_date'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null; } public function getEolDateAttribute($value) { return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null; } public function getEolDateFormattedAttribute($value) { return $this->eol_date ? Carbon::parse($this->eol_date)->format("d M, Y") : ""; } public function getCreatedAtAttribute($date) { return Carbon::parse($date)->format("d M, Y H:m:s a"); } public function getUpdatedAtAttribute($date) { return Carbon::parse($date)->format("d M, Y H:m:s a"); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка