krgm.so-manager-dev.com/app/Models/OpePermission.php
OU.ZAIKOU 13d2ecfceb
All checks were successful
Deploy main / deploy (push) Successful in 25s
【ログイン】二重認証実装
2026-01-21 22:37:38 +09:00

66 lines
1.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OpePermission extends Model
{
// テーブル名
protected $table = 'ope_permission';
// 主キー
protected $primaryKey = 'id';
// created_at / updated_at を使用
public $timestamps = true;
// 一括代入許可カラム
protected $fillable = [
'municipality_id', // 自治体ID外部キー
'feature_id', // 機能ID外部キー
'permission_id', // 操作権限ID外部キー
];
/**
* 機能単位で権限を置換(自治体単位)
* ※ municipality_id + feature_id の組み合わせを置換する
*/
public static function replaceByFeature(
int $municipalityId,
int $featureId,
array $permissionIds
): void {
// ※既存削除
self::query()
->where('municipality_id', $municipalityId)
->where('feature_id', $featureId)
->delete();
// ※新規追加
$permissionIds = array_values(array_unique(array_map('intval', $permissionIds)));
foreach ($permissionIds as $pid) {
self::create([
'municipality_id' => $municipalityId,
'feature_id' => $featureId,
'permission_id' => $pid,
]);
}
}
/**
* 付与済み権限ID一覧を取得自治体単位
*/
public static function getPermissionIds(
int $municipalityId,
int $featureId
): array {
return self::query()
->where('municipality_id', $municipalityId)
->where('feature_id', $featureId)
->pluck('permission_id')
->map(fn ($v) => (int)$v)
->toArray();
}
}