adrema/app/Nami/HasNamiField.php

29 lines
514 B
PHP
Raw Normal View History

2021-08-22 19:31:20 +02:00
<?php
namespace App\Nami;
2023-02-14 14:27:11 +01:00
use Illuminate\Database\Eloquent\Builder;
2021-08-22 19:31:20 +02:00
trait HasNamiField
{
2023-02-05 23:35:08 +01:00
public static function nami(int $id): ?self
2021-08-22 19:31:20 +02:00
{
2023-02-05 23:35:08 +01:00
return static::firstWhere('nami_id', $id);
}
2021-08-22 19:31:20 +02:00
2023-02-05 23:35:08 +01:00
public function getHasNamiAttribute(): bool
{
return null !== $this->nami_id;
2021-08-22 19:31:20 +02:00
}
2023-02-14 14:27:11 +01:00
/**
* @param Builder<self> $query
*
* @return Builder<self>
*/
public static function scopeLocal(Builder $query): Builder
{
return $query->whereNull('nami_id');
}
2021-08-22 19:31:20 +02:00
}