YandexError.php
1.07 KB
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
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;
class YandexError extends Model
{
use SoftDeletes;
protected $table = 'yandex_errors';
protected $fillable = [
'token_id',
'cause_type',
'cause_id',
'service',
'method',
'params',
'errors',
];
protected $casts = [
'params' => 'json',
'errors' => 'array',
];
public function token()
{
return $this->belongsTo(Tokens::class, 'token_id');
}
public function cause()
{
return $this->morphTo('cause');
}
/**
* @param Builder $query
* @param array $filters
* @return Builder
*/
public function scopeFilter($query, array $filters)
{
return $query->when($filters['service'] ?? null, function ($query, $service) {
$query->where('service', $service);
})->when($filters['method'] ?? null, function ($query, $method) {
$query->where('method', $method);
});
}
}