'int', 'booking_id' => 'int', 'value' => 'float', 'is_redeemed' => 'bool', 'issue_date' => 'datetime', 'valid_date' => 'datetime', 'redeem_date' => 'datetime', ]; protected $fillable = [ 'number', 'customer_id', 'booking_id', 'value', 'issue_date', 'valid_date', 'is_redeemed', 'redeem_date', 'text' ]; /** * The "booted" method of the model. * * @return void */ protected static function boot() { parent::boot(); static::created(function ($model) { $model->number = sprintf( '%02u-%05u-%05u-%02u%02u', date('y'), $model->customer_id, $model->id, date('H'), date('i') ); $model->save(); }); } public function create($product) { logger($product->id); } public function booking() { return $this->belongsTo(Booking::class); } public function customer() { return $this->belongsTo(Customer::class); } public function booking_document() { return $this->hasOne(BookingDocument::class, 'coupon_id', 'id'); } public function bookings() { return $this->hasMany(Booking::class); } public function isLegal(){ //TODO // return strtotime(date('Y-m-d')) <= strtotime($this->getValidDate()); return false; } public function getValueFormatted() { return Util::_number_format($this->attributes['value']); } public function getValueRaw() { return $this->attributes['value']; } public function setValueAttribute($value) { $this->attributes['value'] = Util::_clean_float($value); } public function getIssueDateFormatted() { return isset($this->attributes['issue_date']) ? Carbon::parse($this->attributes['issue_date'])->format('d.m.Y') : ''; } public function setIssueDateAttribute($value) { if (!$value) { $this->attributes['issue_date'] = null; } else { $this->attributes['issue_date'] = Carbon::parse($value)->format('Y-m-d'); } } public function getValidDateFormatted() { return isset($this->attributes['valid_date']) ? Carbon::parse($this->attributes['valid_date'])->format('d.m.Y') : ''; } public function setValidDateAttribute($value) { if (!$value) { $this->attributes['valid_date'] = null; } else { $this->attributes['valid_date'] = Carbon::parse($value)->format('Y-m-d'); } } public function getRedeemDateFormatted() { return isset($this->attributes['redeem_date']) ? Carbon::parse($this->attributes['redeem_date'])->format('d.m.Y') : ''; } public function setRedeemDateAttribute($value) { if (!$value) { $this->attributes['redeem_date'] = null; } else { $this->attributes['redeem_date'] = Carbon::parse($value)->format('Y-m-d'); } } }