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 | 3 | public function notes() |
|
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Main Methods |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | /** |
||
44 | * Create a note. |
||
45 | * |
||
46 | * @param string $content |
||
47 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
48 | * @param bool $reload |
||
49 | * |
||
50 | * @return \Arcanedev\LaravelNotes\Models\Note |
||
51 | */ |
||
52 | 3 | public function createNote($content, $author = null, $reload = true) |
|
63 | |||
64 | /** |
||
65 | * Retrieve a note by its ID. |
||
66 | * |
||
67 | * @param int $id |
||
68 | * |
||
69 | * @return \Illuminate\Database\Eloquent\Model |
||
70 | */ |
||
71 | public function findNote($id) |
||
75 | |||
76 | /* ----------------------------------------------------------------- |
||
77 | | Other Methods |
||
78 | | ----------------------------------------------------------------- |
||
79 | */ |
||
80 | |||
81 | /** |
||
82 | * Prepare note attributes. |
||
83 | * |
||
84 | * @param string $content |
||
85 | * @param \Illuminate\Database\Eloquent\Model|null $author |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | 3 | protected function prepareNoteAttributes($content, Model $author = null) |
|
96 | |||
97 | /** |
||
98 | * Get the current author's id. |
||
99 | * |
||
100 | * @return int|null |
||
101 | */ |
||
102 | protected function getCurrentAuthorId() |
||
106 | } |
||
107 |
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.