1 | <?php |
||
7 | trait HasImages |
||
8 | { |
||
9 | /** |
||
10 | * Get a model from a relationship by model name. |
||
11 | * |
||
12 | * @param string $relationship Name of relationship. |
||
13 | * @param string $name Name of model to get. |
||
14 | * |
||
15 | * @return \Illuminate\Database\Eloquent\Model|null |
||
16 | */ |
||
17 | abstract protected function getFromRelationshipByName($relationship, $name); |
||
18 | |||
19 | /** |
||
20 | * A project has many images. |
||
21 | * |
||
22 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
23 | */ |
||
24 | public function images() |
||
28 | |||
29 | /** |
||
30 | * Return true if project has images. |
||
31 | * |
||
32 | * @return bool |
||
33 | */ |
||
34 | public function hasImages() |
||
38 | |||
39 | /** |
||
40 | * Get image by name, if exists. |
||
41 | * |
||
42 | * @param string $name Name of image to get. |
||
43 | * |
||
44 | * @return Larafolio\Models\Image|null |
||
45 | */ |
||
46 | public function image($name) |
||
50 | |||
51 | /** |
||
52 | * Get image url for given size. |
||
53 | * |
||
54 | * @param string $name Name of image to get url for. |
||
55 | * @param string $size Size of image. |
||
56 | * |
||
57 | * @return string|null |
||
58 | */ |
||
59 | public function imageUrl($name, $size = 'medium') |
||
67 | |||
68 | /** |
||
69 | * Get caption for image. |
||
70 | * |
||
71 | * @param string $name Name of image to get caption for. |
||
72 | * |
||
73 | * @return string|null |
||
74 | */ |
||
75 | public function imageCaption($name) |
||
83 | |||
84 | /** |
||
85 | * Get alt for image. |
||
86 | * |
||
87 | * @param string $name Name of image to get caption for. |
||
88 | * |
||
89 | * @return string|null |
||
90 | */ |
||
91 | public function imageAlt($name) |
||
99 | |||
100 | /** |
||
101 | * Return images with all props needed for javascript. |
||
102 | * |
||
103 | * @return Collection |
||
104 | */ |
||
105 | public function imagesWithProps() |
||
112 | } |
||
113 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.