for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace BeyondCode\Vouchers\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
class Voucher extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'model_id',
'model_type',
'code',
'data',
'expires_at'
];
* The attributes that should be mutated to dates.
protected $dates = [
* The attributes that should be cast to native types.
protected $casts = [
'data' => 'collection'
public function __construct(array $attributes = [])
parent::__construct($attributes);
$this->table = config('vouchers.table', 'vouchers');
}
* Get the users who redeemed this voucher.
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
public function users()
return $this->belongsToMany(config('vouchers.user_model'), config('vouchers.relation_table'))->withPivot('redeemed_at');
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
public function model()
return $this->morphTo();
* Check if code is expired.
* @return bool
public function isExpired()
return $this->expires_at ? Carbon::now()->gte($this->expires_at) : false;
* Check if code is not expired.
public function isNotExpired()
return ! $this->isExpired();