|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Models\Traits\CrudTrait; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @mixin IdeHelperBook |
|
10
|
|
|
*/ |
|
11
|
|
|
class Book extends Model |
|
12
|
|
|
{ |
|
13
|
|
|
use CrudTrait; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/* |
|
16
|
|
|
|-------------------------------------------------------------------------- |
|
17
|
|
|
| GLOBAL VARIABLES |
|
18
|
|
|
|-------------------------------------------------------------------------- |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
public $timestamps = false; |
|
22
|
|
|
|
|
23
|
|
|
protected $guarded = ['id']; |
|
24
|
|
|
|
|
25
|
|
|
protected $appends = ['price_with_currency', 'type']; |
|
26
|
|
|
|
|
27
|
|
|
/* |
|
28
|
|
|
|-------------------------------------------------------------------------- |
|
29
|
|
|
| FUNCTIONS |
|
30
|
|
|
|-------------------------------------------------------------------------- |
|
31
|
|
|
*/ |
|
32
|
|
|
|
|
33
|
|
|
/* |
|
34
|
|
|
|-------------------------------------------------------------------------- |
|
35
|
|
|
| RELATIONS |
|
36
|
|
|
|-------------------------------------------------------------------------- |
|
37
|
|
|
*/ |
|
38
|
|
|
|
|
39
|
|
|
/* |
|
40
|
|
|
|-------------------------------------------------------------------------- |
|
41
|
|
|
| SCOPES |
|
42
|
|
|
|-------------------------------------------------------------------------- |
|
43
|
|
|
*/ |
|
44
|
|
|
|
|
45
|
|
|
/* |
|
46
|
|
|
|-------------------------------------------------------------------------- |
|
47
|
|
|
| ACCESORS |
|
48
|
|
|
|-------------------------------------------------------------------------- |
|
49
|
|
|
*/ |
|
50
|
|
|
|
|
51
|
|
|
public function getPriceAttribute($value) |
|
52
|
|
|
{ |
|
53
|
|
|
return $value / 100; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getPriceWithCurrencyAttribute() |
|
57
|
|
|
{ |
|
58
|
|
|
if (config('app.currency_position') === 'before') { |
|
59
|
|
|
return config('app.currency_symbol').' '.$this->price; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $this->price.' '.config('app.currency_symbol'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getTypeAttribute() |
|
66
|
|
|
{ |
|
67
|
|
|
return 'book'; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/* |
|
71
|
|
|
|-------------------------------------------------------------------------- |
|
72
|
|
|
| MUTATORS |
|
73
|
|
|
|-------------------------------------------------------------------------- |
|
74
|
|
|
*/ |
|
75
|
|
|
|
|
76
|
|
|
public function setPriceAttribute($value) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->attributes['price'] = $value * 100; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|