45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Backpack\CRUD\app\Models\Traits\SpatieTranslatable\HasTranslations;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Document extends Model
|
|
{
|
|
use \Backpack\CRUD\app\Models\Traits\CrudTrait;
|
|
use HasFactory;
|
|
use HasTranslations;
|
|
|
|
protected $guarded = [''];
|
|
public $translatable = ['title', 'file'];
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
static::deleting(function($obj) {
|
|
\Storage::disk('uploads')->delete($obj->image);
|
|
});
|
|
}
|
|
|
|
public function setFileAttribute($value)
|
|
{
|
|
$attribute_name = "file";
|
|
$disk = config('backpack.base.root_disk_name');
|
|
$destination_path = "public/uploads/documents";
|
|
|
|
$this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path, $fileName = null);
|
|
|
|
return $this->attributes[$attribute_name]; // uncomment if this is a translatable field
|
|
|
|
}
|
|
|
|
public function documentCategory()
|
|
{
|
|
return $this->belongsTo(DocumentCategory::class);
|
|
}
|
|
|
|
}
|