1 | <?php namespace Arcanedev\LaravelNotes\Traits; |
||
13 | trait HasOneNote |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Relationships |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | /** |
||
21 | * Relation to ONE note. |
||
22 | * |
||
23 | * @return \Illuminate\Database\Eloquent\Relations\MorphOne |
||
24 | */ |
||
25 | 15 | public function note() |
|
29 | |||
30 | /* ----------------------------------------------------------------- |
||
31 | | Main Methods |
||
32 | | ----------------------------------------------------------------- |
||
33 | */ |
||
34 | |||
35 | /** |
||
36 | * Create a note. |
||
37 | * |
||
38 | * @param string $content |
||
39 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
40 | * @param bool $reload |
||
41 | * |
||
42 | * @return \Arcanedev\LaravelNotes\Models\Note |
||
43 | */ |
||
44 | 15 | public function createNote($content, $author = null, $reload = true) |
|
57 | |||
58 | /** |
||
59 | * Update a note. |
||
60 | * |
||
61 | * @param string $content |
||
62 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
63 | * @param bool $reload |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | 3 | public function updateNote($content, Model $author = null, $reload = true) |
|
77 | |||
78 | /* ----------------------------------------------------------------- |
||
79 | | Other Methods |
||
80 | | ----------------------------------------------------------------- |
||
81 | */ |
||
82 | |||
83 | /** |
||
84 | * Prepare note attributes. |
||
85 | * |
||
86 | * @param string $content |
||
87 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | 15 | protected function prepareNoteAttributes($content, Model $author = null) |
|
98 | |||
99 | /** |
||
100 | * Get the current author's id. |
||
101 | * |
||
102 | * @return int|null |
||
103 | */ |
||
104 | 12 | protected function getCurrentAuthorId() |
|
108 | } |
||
109 |
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.