|
- <?php
-
- namespace App\Models\Feature;
-
- use App\Models\ColumnName;
- use App\Models\Contract;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use LogicException;
-
- trait ContractFeature
- {
- const COL_NAME_CONTRACT_ID = ColumnName::CONTRACT_ID;
-
- public function setContract(Contract|string $contract): static
- {
- $id = is_string($contract) ? $contract : $contract->id;
- data_set($this, self::COL_NAME_CONTRACT_ID, $id);
- return $this;
- }
-
- public function contract(): BelongsTo
- {
- if ($this instanceof Model) {
- return $this->belongsTo(Contract::class);
- } else {
- throw new LogicException("不正");
- }
- }
- }
|