1 | <?php namespace Arcanedev\LaravelNotes\Traits; |
||
15 | trait HasManyNotes |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Relationships |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | /** |
||
23 | * The notes relationship. |
||
24 | * |
||
25 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
26 | */ |
||
27 | 15 | public function notes() |
|
31 | |||
32 | /* ----------------------------------------------------------------- |
||
33 | | Main Methods |
||
34 | | ----------------------------------------------------------------- |
||
35 | */ |
||
36 | |||
37 | /** |
||
38 | * Create a note. |
||
39 | * |
||
40 | * @param string $content |
||
41 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
42 | * @param bool $reload |
||
43 | * |
||
44 | * @return \Arcanedev\LaravelNotes\Models\Note |
||
45 | */ |
||
46 | 15 | public function createNote($content, $author = null, $reload = true) |
|
59 | |||
60 | /** |
||
61 | * Retrieve a note by its ID. |
||
62 | * |
||
63 | * @param int $id |
||
64 | * |
||
65 | * @return \Illuminate\Database\Eloquent\Model |
||
66 | */ |
||
67 | 3 | public function findNote($id) |
|
71 | |||
72 | /* ----------------------------------------------------------------- |
||
73 | | Other Methods |
||
74 | | ----------------------------------------------------------------- |
||
75 | */ |
||
76 | |||
77 | /** |
||
78 | * Prepare note attributes. |
||
79 | * |
||
80 | * @param string $content |
||
81 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
82 | * |
||
83 | * @return array |
||
84 | */ |
||
85 | 15 | protected function prepareNoteAttributes($content, Model $author = null) |
|
92 | |||
93 | /** |
||
94 | * Get the current author's id. |
||
95 | * |
||
96 | * @return int|null |
||
97 | */ |
||
98 | 6 | protected function getCurrentAuthorId() |
|
102 | } |
||
103 |
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.