1 | <?php |
||
15 | trait PrimarySlug |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Primary slug column of this model. |
||
20 | * |
||
21 | * @return string |
||
22 | */ |
||
23 | public function getSlugKeyName() |
||
31 | |||
32 | /** |
||
33 | * Primary slug value of this model. |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | public function getSlugKey() |
||
41 | |||
42 | /** |
||
43 | * Query scope for finding a model by primary slug. |
||
44 | * |
||
45 | * @param Builder $scope |
||
46 | * @param string $slug |
||
47 | * @return Builder |
||
48 | */ |
||
49 | public function scopeWhereSlug($scope, $slug) |
||
53 | |||
54 | /** |
||
55 | * Find Model by primary slug. Fallback to find by id. Fail if not found. |
||
56 | * |
||
57 | * @param string $slug |
||
58 | * @return Model|Collection|null |
||
59 | */ |
||
60 | public static function findBySlug($slug) |
||
64 | |||
65 | /** |
||
66 | * Find by primary slug. Fail if not found. |
||
67 | * |
||
68 | * @param string $slug |
||
69 | * @return Model |
||
70 | */ |
||
71 | public static function findBySlugOrFail($slug) |
||
75 | |||
76 | } |
||
77 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: