51 lines
1.0 KiB
PHP
51 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class PointFile extends Model
|
|
{
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'id',
|
|
'point_fileable_id',
|
|
'point_fileable_type',
|
|
'created_at',
|
|
'updated_at'
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'path',
|
|
'point_fileable_id',
|
|
'point_fileable_type',
|
|
];
|
|
|
|
/**
|
|
* Get the owning point_fileable model.
|
|
*/
|
|
public function point_fileable(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
protected function path(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn($value) => $value == null ? null : Storage::disk('public')->url($value)
|
|
);
|
|
}
|
|
}
|