|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\NewsCRUD\app\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Backpack\CRUD\CrudTrait; |
|
7
|
|
|
use Cviebrock\EloquentSluggable\Sluggable; |
|
8
|
|
|
|
|
9
|
|
|
class Tag extends Model |
|
10
|
|
|
{ |
|
11
|
|
|
use CrudTrait; |
|
12
|
|
|
use Sluggable; |
|
13
|
|
|
|
|
14
|
|
|
/* |
|
15
|
|
|
|-------------------------------------------------------------------------- |
|
16
|
|
|
| GLOBAL VARIABLES |
|
17
|
|
|
|-------------------------------------------------------------------------- |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
protected $table = 'tags'; |
|
21
|
|
|
protected $primaryKey = 'id'; |
|
22
|
|
|
public $timestamps = true; |
|
23
|
|
|
// protected $guarded = ['id']; |
|
|
|
|
|
|
24
|
|
|
protected $fillable = ['name']; |
|
25
|
|
|
// protected $hidden = []; |
|
|
|
|
|
|
26
|
|
|
// protected $dates = []; |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Return the sluggable configuration array for this model. |
|
30
|
|
|
* |
|
31
|
|
|
* @return array |
|
|
|
|
|
|
32
|
|
|
*/ |
|
33
|
|
|
public function sluggable() |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
36
|
|
|
'slug' => [ |
|
37
|
|
|
'source' => 'slug_or_name', |
|
38
|
|
|
], |
|
39
|
|
|
]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/* |
|
43
|
|
|
|-------------------------------------------------------------------------- |
|
44
|
|
|
| FUNCTIONS |
|
45
|
|
|
|-------------------------------------------------------------------------- |
|
46
|
|
|
*/ |
|
47
|
|
|
|
|
48
|
|
|
/* |
|
49
|
|
|
|-------------------------------------------------------------------------- |
|
50
|
|
|
| RELATIONS |
|
51
|
|
|
|-------------------------------------------------------------------------- |
|
52
|
|
|
*/ |
|
53
|
|
|
|
|
54
|
|
|
public function articles() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->hasMany('Backpack\NewsCRUD\app\Models\Article'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/* |
|
60
|
|
|
|-------------------------------------------------------------------------- |
|
61
|
|
|
| SCOPES |
|
62
|
|
|
|-------------------------------------------------------------------------- |
|
63
|
|
|
*/ |
|
64
|
|
|
|
|
65
|
|
|
/* |
|
66
|
|
|
|-------------------------------------------------------------------------- |
|
67
|
|
|
| ACCESORS |
|
68
|
|
|
|-------------------------------------------------------------------------- |
|
69
|
|
|
*/ |
|
70
|
|
|
|
|
71
|
|
|
// The slug is created automatically from the "name" field if no slug exists. |
|
72
|
|
|
public function getSlugOrNameAttribute() |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
if ($this->slug != '') { |
|
|
|
|
|
|
75
|
|
|
return $this->slug; |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->name; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/* |
|
82
|
|
|
|-------------------------------------------------------------------------- |
|
83
|
|
|
| MUTATORS |
|
84
|
|
|
|-------------------------------------------------------------------------- |
|
85
|
|
|
*/ |
|
86
|
|
|
} |
|
87
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.