Completed
Push — master ( 2d22de...e2d103 )
by Sherif
02:14
created

Setting::getCreatedAtAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php namespace App\Modules\Core;
2
3
use Illuminate\Database\Eloquent\Model;
4
use Illuminate\Database\Eloquent\SoftDeletes;
5
6
class Setting extends Model
7
{
8
9
    use SoftDeletes;
10
    protected $table    = 'settings';
11
    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
    protected $hidden   = ['deleted_at'];
13
    protected $guarded  = ['id', 'key'];
14
    protected $fillable = ['name', 'value'];
15
    public $searchable  = ['name', 'value', 'key'];
16
    
17
    public function getCreatedAtAttribute($value)
18
    {
19
        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
20
    }
21
22
    public function getUpdatedAtAttribute($value)
23
    {
24
        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
25
    }
26
27
    public function getDeletedAtAttribute($value)
28
    {
29
        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
30
    }
31
    
32
    public function newCollection(array $models = [])
33
    {
34
        return parent::newCollection($models)->keyBy('key');
35
    }
36
37
    public static function boot()
38
    {
39
        parent::boot();
40
        Setting::observe(\App::make('App\Modules\Core\ModelObservers\SettingsObserver'));
41
    }
42
}
43