/
Notice.php
47 lines (37 loc) · 922 Bytes
/
Notice.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
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Notice extends Model
{
public function user()
{
return $this->belongsTo('App\User');
}
public function uri($objectType = "note")
{
$tag = 'example.org';
$timestamp = $this->created_at->format('Y-M-d');
$id = $this->id;
switch ($objectType) {
case 'note':
$res = "tag:$tag,$timestamp:noticeId=$id:objectType=$objectType";
break;
case 'thread':
$res = "tag:$tag,$timestamp:objectType=$objectType:nonce=".str_random(16);
break;
default:
$res = "tag:$tag,$timestamp:noticeId=$id:objectType=$objectType";
break;
}
return $res;
}
public function url()
{
$domain = config('app.url');
return "{$domain}/notice/{$this->id}";
}
public function favorites()
{
return $this->hasMany('App\Favorite');
}
}