| 1 | <?php |
||
| 8 | class Token extends Model |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * The table associated with the model. |
||
| 12 | * |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected $table = 'tokens'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The attributes that are mass assignable. |
||
| 19 | * |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | protected $fillable = [ |
||
| 23 | 'api_token', |
||
| 24 | 'expired_at', |
||
| 25 | ]; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * The attributes that should be mutated to dates. |
||
| 29 | * |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | protected $dates = ['expired_at']; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Set the expired timestamp value. |
||
| 36 | * |
||
| 37 | * @param mixed $value |
||
| 38 | * @return void |
||
| 39 | */ |
||
| 40 | public function setExpiredAtAttribute($value) |
||
| 41 | { |
||
| 42 | if (! is_null($value) && ! $value instanceof Carbon) { |
||
| 43 | $value = Carbon::parse($value); |
||
| 44 | } |
||
| 45 | |||
| 46 | $this->attributes['expired_at'] = $value; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Determine if the token is expired or not. |
||
| 51 | * |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | public function isExpired() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Determine if the token is not expired. |
||
| 65 | * |
||
| 66 | * @return bool |
||
| 67 | */ |
||
| 68 | public function isNotExpired() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get the user that owns the token. |
||
| 75 | * |
||
| 76 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
| 77 | */ |
||
| 78 | public function user() |
||
| 82 | } |
||
| 83 |