1 | <?php namespace Arcanedev\LaravelNotes\Traits; |
||
15 | trait HasOneNote |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Traits |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | use ConfigHelper; |
||
23 | |||
24 | /* ----------------------------------------------------------------- |
||
25 | | Relationships |
||
26 | | ----------------------------------------------------------------- |
||
27 | */ |
||
28 | |||
29 | /** |
||
30 | * Relation to ONE note. |
||
31 | * |
||
32 | * @return \Illuminate\Database\Eloquent\Relations\MorphOne |
||
33 | */ |
||
34 | 15 | public function note() |
|
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Main Methods |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * Create a note. |
||
46 | * |
||
47 | * @param string $content |
||
48 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
49 | * @param bool $reload |
||
50 | * |
||
51 | * @return \Arcanedev\LaravelNotes\Models\Note |
||
52 | */ |
||
53 | 15 | public function createNote($content, $author = null, $reload = true) |
|
66 | |||
67 | /** |
||
68 | * Update a note. |
||
69 | * |
||
70 | * @param string $content |
||
71 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
72 | * @param bool $reload |
||
73 | * |
||
74 | * @return bool |
||
75 | */ |
||
76 | 3 | public function updateNote($content, Model $author = null, $reload = true) |
|
86 | |||
87 | /* ----------------------------------------------------------------- |
||
88 | | Other Methods |
||
89 | | ----------------------------------------------------------------- |
||
90 | */ |
||
91 | |||
92 | /** |
||
93 | * Prepare note attributes. |
||
94 | * |
||
95 | * @param string $content |
||
96 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | 15 | protected function prepareNoteAttributes($content, Model $author = null) |
|
107 | |||
108 | /** |
||
109 | * Get the current author's id. |
||
110 | * |
||
111 | * @return int|null |
||
112 | */ |
||
113 | 12 | protected function getCurrentAuthorId() |
|
117 | } |
||
118 |
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.