|
@@ -129,12 +129,24 @@ public function delete(int $id): bool
|
|
|
public function getUserTypes(): \Illuminate\Database\Eloquent\Collection
|
|
public function getUserTypes(): \Illuminate\Database\Eloquent\Collection
|
|
|
{
|
|
{
|
|
|
$scope = request()->input('access_scope', Auth::user()?->access_scope);
|
|
$scope = request()->input('access_scope', Auth::user()?->access_scope);
|
|
|
- $unitId = request()->input('active_unit_id') ?? Auth::user()?->units()->value('units.id');
|
|
|
|
|
|
|
+ $isFranchisorAssignment = request()->is('api/user/all/types');
|
|
|
|
|
+ $unitId = request()->integer('unit_id')
|
|
|
|
|
+ ?: request()->input('active_unit_id')
|
|
|
|
|
+ ?: Auth::user()?->units()->value('units.id');
|
|
|
|
|
|
|
|
return \App\Models\UserType::query()
|
|
return \App\Models\UserType::query()
|
|
|
- ->when($scope === 'unit', fn ($query) => $query->where('unit_id', $unitId))
|
|
|
|
|
|
|
+ ->when($scope === 'unit' && $unitId, fn ($query) => $query->where('unit_id', $unitId))
|
|
|
|
|
+ ->when($scope === 'unit' && !$unitId, fn ($query) => $query->where('system_key', 'ADMIN_FRANCHISEE'))
|
|
|
->when($scope === 'franchisor', fn ($query) => $query->whereNull('unit_id'))
|
|
->when($scope === 'franchisor', fn ($query) => $query->whereNull('unit_id'))
|
|
|
- ->where('is_system', false)
|
|
|
|
|
|
|
+ ->when(
|
|
|
|
|
+ $scope === 'unit' && $isFranchisorAssignment,
|
|
|
|
|
+ fn ($query) => $query->where(
|
|
|
|
|
+ fn ($types) => $types
|
|
|
|
|
+ ->where('is_system', false)
|
|
|
|
|
+ ->orWhere('system_key', 'ADMIN_FRANCHISEE'),
|
|
|
|
|
+ ),
|
|
|
|
|
+ fn ($query) => $query->where('is_system', false),
|
|
|
|
|
+ )
|
|
|
->orderBy('label')
|
|
->orderBy('label')
|
|
|
->get();
|
|
->get();
|
|
|
}
|
|
}
|