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