1 | <?php |
||
10 | trait HasSpecificationsTrait |
||
11 | { |
||
12 | /** |
||
13 | * ScoreModel class name. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected static $scoreModelClass = ScoreModel::class; |
||
18 | |||
19 | /** |
||
20 | * Instance of Specifications. |
||
21 | * |
||
22 | * @var \Pbmedia\Specifications\Specifications |
||
23 | */ |
||
24 | protected $specifications; |
||
25 | |||
26 | /** |
||
27 | * Returns a Specifications object with the Scores and Attributes |
||
28 | * loaded from the database. |
||
29 | * |
||
30 | * @return \Pbmedia\Specifications\Specifications |
||
31 | */ |
||
32 | public function specifications(): Specifications |
||
44 | |||
45 | /** |
||
46 | * Defines the relationship with the Scores attached to this model. |
||
47 | * |
||
48 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
49 | */ |
||
50 | public function Scores(): MorphMany |
||
54 | |||
55 | /** |
||
56 | * Binds a callback to the 'saved' event of the model which syncs the |
||
57 | * AttributeScore objects in the Specifications instance with |
||
58 | * ones in the database. |
||
59 | */ |
||
60 | public static function bootHasSpecificationsTrait() |
||
85 | } |
||
86 |
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.