1 | <?php |
||
10 | class Redirect extends Model implements RedirectModelContract |
||
11 | { |
||
12 | /** |
||
13 | * The database table. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $table = 'redirects'; |
||
18 | |||
19 | /** |
||
20 | * The attributes that are mass assignable. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $fillable = [ |
||
25 | 'old_url', |
||
26 | 'new_url', |
||
27 | 'status', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Boot the model. |
||
32 | * |
||
33 | * @return void |
||
34 | */ |
||
35 | public static function boot() |
||
49 | |||
50 | /** |
||
51 | * The mutator to set the "old_url" attribute. |
||
52 | * |
||
53 | * @param string $value |
||
54 | */ |
||
55 | public function setOldUrlAttribute($value) |
||
59 | |||
60 | /** |
||
61 | * The mutator to set the "new_url" attribute. |
||
62 | * |
||
63 | * @param string $value |
||
64 | */ |
||
65 | public function setNewUrlAttribute($value) |
||
69 | |||
70 | /** |
||
71 | * Filter the query by an old url. |
||
72 | * |
||
73 | * @param Builder $query |
||
74 | * @param string $url |
||
75 | * |
||
76 | * @return mixed |
||
77 | */ |
||
78 | public function scopeWhereOldUrl($query, string $url) |
||
82 | |||
83 | /** |
||
84 | * Filter the query by a new url. |
||
85 | * |
||
86 | * @param Builder $query |
||
87 | * @param string $url |
||
88 | * |
||
89 | * @return mixed |
||
90 | */ |
||
91 | public function scopeWhereNewUrl($query, string $url) |
||
95 | |||
96 | /** |
||
97 | * Get all redirect statuses defined inside the "config/redirects.php" file. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | public static function getStatuses(): array |
||
105 | |||
106 | /** |
||
107 | * Sync old redirects to point to the new (final) url. |
||
108 | * |
||
109 | * @param RedirectModelContract $model |
||
110 | * @param string $finalUrl |
||
111 | * @return void |
||
112 | */ |
||
113 | public function syncOldRedirects(RedirectModelContract $model, string $finalUrl): void |
||
122 | |||
123 | /** |
||
124 | * Return a valid redirect entity for a given path (old url). |
||
125 | * A redirect is valid if: |
||
126 | * - it has an url to redirect to (new url) |
||
127 | * - it's status code is one of the statuses defined on this model. |
||
128 | * |
||
129 | * @param string $path |
||
130 | * @return Redirect|null |
||
131 | */ |
||
132 | public static function findValidOrNull($path): ?RedirectModelContract |
||
139 | } |
||
140 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: