1 | <?php |
||
5 | trait HasImages |
||
6 | { |
||
7 | /** |
||
8 | * A project has many images. |
||
9 | * |
||
10 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
11 | */ |
||
12 | public function images() |
||
16 | |||
17 | /** |
||
18 | * Return true if project has images. |
||
19 | * |
||
20 | * @return bool |
||
21 | */ |
||
22 | public function hasImages() |
||
26 | |||
27 | /** |
||
28 | * Get image by name, if exists. |
||
29 | * |
||
30 | * @param string $name Name of image to get. |
||
31 | * |
||
32 | * @return Larafolio\Models\Image|null |
||
33 | */ |
||
34 | public function image($name) |
||
38 | |||
39 | /** |
||
40 | * Get image url for given size. |
||
41 | * |
||
42 | * @param string $name Name of image to get url for. |
||
43 | * @param string $size Size of image. |
||
44 | * |
||
45 | * @return string|null |
||
46 | */ |
||
47 | public function imageUrl($name, $size = 'medium') |
||
55 | |||
56 | /** |
||
57 | * Get caption for image. |
||
58 | * |
||
59 | * @param string $name Name of image to get caption for. |
||
60 | * |
||
61 | * @return string|null |
||
62 | */ |
||
63 | public function imageCaption($name) |
||
71 | |||
72 | /** |
||
73 | * Get alt for image. |
||
74 | * |
||
75 | * @param string $name Name of image to get caption for. |
||
76 | * |
||
77 | * @return string|null |
||
78 | */ |
||
79 | public function imageAlt($name) |
||
87 | } |
||
88 |
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.