Passed
Push — feature/resources ( 00a731...ac736e )
by Yonathan
05:58 queued 12s
created

Resource::setFileAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Backpack\CRUD\app\Models\Traits\CrudTrait;
7
use Backpack\CRUD\app\Models\Traits\SpatieTranslatable\HasTranslations;
8
9
/**
10
 * Class Resource
11
 *
12
 * @property int id
13
 * @property string name
14
 * @property string file
15
 */
16
17
class Resource extends Model
18
{
19
    use CrudTrait;
20
    use HasTranslations;
21
22
    /**
23
     * The model's attibutes that admin cannot change.
24
     *
25
     * @var array
26
     */
27
    protected $guarded = ['id'];
28
29
    /**
30
     * The model's attributes that are mass assignable.
31
     *
32
     * @var array
33
     */
34
    protected $fillable = ['name', 'file'];
35
36
    /**
37
     * The model's attributes that are translated.
38
     *
39
     * @var array
40
     */
41
    protected $translatable = ['name'];
42
43
    /**
44
     * Set the value of file name attribute in DB and upload file to disk.
45
     *
46
     */
47
    public function setFileAttribute($value)
48
    {
49
        $this->uploadFileToDisk($value, 'file', 'public', 'resources');
50
    }
51
}
52