Total Complexity | 3 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | class Resource extends Model |
||
19 | { |
||
20 | use CrudTrait; |
||
21 | use HasTranslations; |
||
22 | |||
23 | /** |
||
24 | * Delete file in resources folder |
||
25 | * |
||
26 | */ |
||
27 | public static function boot(): void |
||
28 | { |
||
29 | parent::boot(); |
||
30 | static::deleting(function ($obj): void { |
||
31 | Storage::disk('public')->delete($obj->file); |
||
32 | }); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * The model's attibutes that admin cannot change. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $guarded = ['id']; |
||
41 | |||
42 | /** |
||
43 | * The model's attributes that are mass assignable. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $fillable = ['name', 'file']; |
||
48 | |||
49 | /** |
||
50 | * The model's attributes that are translated. |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $translatable = ['name']; |
||
55 | |||
56 | /** |
||
57 | * Set the value of file name attribute in DB and upload file to disk. |
||
58 | * |
||
59 | * @param string $value Incoming value for 'file' attribute. |
||
60 | */ |
||
61 | public function setFileAttribute(string $value): void |
||
70 | } |
||
71 | } |
||
73 |