1 | <?php namespace Arcanedev\LaravelNotes\Traits; |
||
15 | trait HasManyNotes |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Traits |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | use ConfigHelper; |
||
23 | |||
24 | /* ----------------------------------------------------------------- |
||
25 | | Relationships |
||
26 | | ----------------------------------------------------------------- |
||
27 | */ |
||
28 | |||
29 | /** |
||
30 | * The notes relationship. |
||
31 | * |
||
32 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
33 | */ |
||
34 | 9 | public function notes() |
|
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 | 9 | public function createNote($content, $author = null, $reload = true) |
|
64 | |||
65 | /** |
||
66 | * Retrieve a note by its ID. |
||
67 | * |
||
68 | * @param int $id |
||
69 | * |
||
70 | * @return \Illuminate\Database\Eloquent\Model |
||
71 | */ |
||
72 | 3 | public function findNote($id) |
|
76 | |||
77 | /* ----------------------------------------------------------------- |
||
78 | | Other Methods |
||
79 | | ----------------------------------------------------------------- |
||
80 | */ |
||
81 | |||
82 | /** |
||
83 | * Prepare note attributes. |
||
84 | * |
||
85 | * @param string $content |
||
86 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | 9 | protected function prepareNoteAttributes($content, Model $author = null) |
|
97 | |||
98 | /** |
||
99 | * Get the current author's id. |
||
100 | * |
||
101 | * @return int|null |
||
102 | */ |
||
103 | 6 | protected function getCurrentAuthorId() |
|
107 | } |
||
108 |
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.