/
ApiKey.php
56 lines (46 loc) · 1.07 KB
/
ApiKey.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Api;
use Carbon\Carbon;
use Flarum\Database\AbstractModel;
use Flarum\User\User;
use Illuminate\Support\Str;
/**
* @property int $id
* @property string $key
* @property string|null $allowed_ips
* @property string|null $scopes
* @property int|null $user_id
* @property \Flarum\User\User|null $user
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon|null $last_activity_at
*/
class ApiKey extends AbstractModel
{
protected $dates = ['last_activity_at'];
/**
* Generate an API key.
*
* @return static
*/
public static function generate()
{
$key = new static;
$key->key = Str::random(40);
return $key;
}
public function touch()
{
$this->last_activity_at = Carbon::now();
return $this->save();
}
public function user()
{
return $this->belongsTo(User::class);
}
}