mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Use more modern mutator/accessory syntax
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
b0ddb26e73
commit
1cdec61be6
|
@ -10,7 +10,7 @@ use App\Http\Traits\UniqueUndeletedTrait;
|
|||
use App\Models\Traits\Acceptable;
|
||||
use App\Models\Traits\Searchable;
|
||||
use App\Presenters\Presentable;
|
||||
use AssetPresenter;
|
||||
use App\Presenters\AssetPresenter;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
@ -19,6 +19,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Model for Assets.
|
||||
|
@ -28,7 +30,7 @@ use Watson\Validating\ValidatingTrait;
|
|||
class Asset extends Depreciable
|
||||
{
|
||||
|
||||
protected $presenter = \App\Presenters\AssetPresenter::class;
|
||||
protected $presenter = AssetPresenter::class;
|
||||
|
||||
use CompanyableTrait;
|
||||
use HasFactory, Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait;
|
||||
|
@ -973,59 +975,39 @@ class Asset extends Depreciable
|
|||
* @param $value
|
||||
* @return void
|
||||
*/
|
||||
public function getNextAuditDateAttribute($value)
|
||||
|
||||
protected function nextAuditDate(): Attribute
|
||||
{
|
||||
return $this->attributes['next_audit_date'] = $value ? Carbon::parse($value)->format('Y-m-d') : null;
|
||||
return Attribute::make(
|
||||
get: fn ($value) => $value ? Carbon::parse($value)->format('Y-m-d') : null,
|
||||
set: fn ($value) => $value ? Carbon::parse($value)->format('Y-m-d') : null,
|
||||
);
|
||||
}
|
||||
|
||||
public function setNextAuditDateAttribute($value)
|
||||
protected function lastCheckout(): Attribute
|
||||
{
|
||||
$this->attributes['next_audit_date'] = $value ? Carbon::parse($value)->format('Y-m-d') : null;
|
||||
return Attribute::make(
|
||||
get: fn ($value) => $value ? Carbon::parse($value)->format('Y-m-d H:i:s') : null,
|
||||
set: fn ($value) => $value ? Carbon::parse($value)->format('Y-m-d H:i:s') : null,
|
||||
);
|
||||
}
|
||||
|
||||
public function getLastCheckoutAttribute($value)
|
||||
protected function lastCheckin(): Attribute
|
||||
{
|
||||
return $this->attributes['last_checkout'] = $value ? Carbon::parse($value)->format('Y-m-d H:i:s') : null;
|
||||
return Attribute::make(
|
||||
get: fn ($value) => $value ? Carbon::parse($value)->format('Y-m-d H:i:s') : null,
|
||||
set: fn ($value) => $value ? Carbon::parse($value)->format('Y-m-d H:i:s') : null,
|
||||
);
|
||||
}
|
||||
|
||||
public function setLastCheckoutAttribute($value)
|
||||
protected function assetEolDate(): Attribute
|
||||
{
|
||||
$this->attributes['last_checkout'] = $value ? Carbon::parse($value)->format('Y-m-d H:i:s') : null;
|
||||
return Attribute::make(
|
||||
get: fn ($value) => $value ? Carbon::parse($value)->format('Y-m-d') : null,
|
||||
set: fn ($value) => $value ? Carbon::parse($value)->format('Y-m-d') : null,
|
||||
);
|
||||
}
|
||||
|
||||
public function getLastCheckinAttribute($value)
|
||||
{
|
||||
return $this->attributes['last_checkin'] = $value ? Carbon::parse($value)->format('Y-m-d H:i:s') : null;
|
||||
}
|
||||
|
||||
public function setLastCheckinAttribute($value)
|
||||
{
|
||||
$this->attributes['last_checkin'] = $value ? Carbon::parse($value)->format('Y-m-d H:i:s') : null;
|
||||
}
|
||||
|
||||
public function getLastAuditDateAttribute($value)
|
||||
{
|
||||
return $this->attributes['last_audit_date'] = $value ? Carbon::parse($value)->format('Y-m-d H:i:s') : null;
|
||||
}
|
||||
|
||||
public function setLastAuditDateAttribute($value)
|
||||
{
|
||||
$this->attributes['last_audit_date'] = $value ? Carbon::parse($value)->format('Y-m-d H:i:s') : null;
|
||||
}
|
||||
|
||||
public function getAssetEolDateAttribute($value)
|
||||
{
|
||||
return $this->attributes['asset_eol_date'] = $value ? Carbon::parse($value)->format('Y-m-d') : null;
|
||||
}
|
||||
|
||||
public function setAssetEolDateAttribute($value)
|
||||
{
|
||||
$this->attributes['asset_eol_date'] = $value ? Carbon::parse($value)->format('Y-m-d') : null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This sets the requestable to a boolean 0 or 1. This accounts for forms or API calls that
|
||||
* explicitly pass the requestable field but it has a null or empty value.
|
||||
|
@ -1035,9 +1017,13 @@ class Asset extends Depreciable
|
|||
* @param $value
|
||||
* @return void
|
||||
*/
|
||||
public function setRequestableAttribute($value)
|
||||
|
||||
protected function requestable(): Attribute
|
||||
{
|
||||
$this->attributes['requestable'] = (int) filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||
return Attribute::make(
|
||||
get: fn ($value) => (int) filter_var($value, FILTER_VALIDATE_BOOLEAN),
|
||||
set: fn ($value) => (int) filter_var($value, FILTER_VALIDATE_BOOLEAN),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue