aboutsummaryrefslogtreecommitdiff
path: root/src/CamilStaps/BotleaguesApi/Database/UserToken.php
blob: 92b03b81270f5c3a3c4a92b691b9e71d09bcb528 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
namespace CamilStaps\BotleaguesApi\Database;

class UserToken extends Model {
    
    protected $table = 'user_tokens';
    protected $hidden = ['token'];
    protected $fillable = ['userId', 'token', 'valid_till'];
    protected $dates = ['created_at', 'updated_at', 'valid_till'];

    /**
     * Override the parent's save() function to automatically update the valid_till timestamp
     */
    public function save(array $options = array()) {
        $this->valid_till = date("Y-m-d H:i:s", time() + 3600);

        return parent::save($options);
    }

    public function getValidTillAttribute($attr) {
        return $this->formatDate($attr);
    }

}