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