| 1 | <?php namespace Bedard\Shop\Models; |
||
| 8 | class Promotion extends Model |
||
| 9 | { |
||
| 10 | use \Bedard\Shop\Traits\Amountable, |
||
| 11 | \Bedard\Shop\Traits\StartEndable, |
||
| 12 | \Bedard\Shop\Traits\Timeable, |
||
| 13 | \October\Rain\Database\Traits\Purgeable, |
||
| 14 | \October\Rain\Database\Traits\Validation; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string The database table used by the model. |
||
| 18 | */ |
||
| 19 | public $table = 'bedard_shop_promotions'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var array Default attributes |
||
| 23 | */ |
||
| 24 | public $attributes = [ |
||
| 25 | 'amount' => 0, |
||
| 26 | 'is_percentage' => true, |
||
| 27 | 'minimum_cart_value' => 0, |
||
| 28 | ]; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var array Attribute casting |
||
| 32 | */ |
||
| 33 | public $casts = [ |
||
| 34 | 'amount' => 'float', |
||
| 35 | 'is_percentage' => 'boolean', |
||
| 36 | ]; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var array Guarded fields |
||
| 40 | */ |
||
| 41 | protected $guarded = ['*']; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var array Fillable fields |
||
| 45 | */ |
||
| 46 | protected $fillable = [ |
||
| 47 | 'amount', |
||
| 48 | 'is_percentage', |
||
| 49 | 'message', |
||
| 50 | 'minimum_cart_value', |
||
| 51 | 'name', |
||
| 52 | ]; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var array Purgeable vields |
||
| 56 | */ |
||
| 57 | protected $purgeable = []; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var array Validation rules |
||
| 61 | */ |
||
| 62 | public $rules = [ |
||
| 63 | 'end_at' => 'date', |
||
| 64 | 'minimum_cart_value' => 'numeric|min:0', |
||
| 65 | 'name' => 'required', |
||
| 66 | 'start_at' => 'date', |
||
| 67 | ]; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var array Relations |
||
| 71 | */ |
||
| 72 | public $hasMany = [ |
||
| 73 | 'carts' => [ |
||
| 74 | 'Bedard\Shop\Models\Cart', |
||
| 75 | ], |
||
| 76 | ]; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Filter form fields. |
||
| 80 | * |
||
| 81 | * @param object $fields |
||
| 82 | * @return void |
||
| 83 | */ |
||
| 84 | public function filterFields($fields) |
||
| 89 | } |
||
| 90 |