feat(outlet): Implement user auto-assignment to new outlets based on roles for improved management efficiency.
This commit is contained in:
parent
d7e870720f
commit
c1acb637b9
@ -6,6 +6,7 @@
|
||||
use App\Enums\OutletStatus;
|
||||
use App\Models\OpeningHour;
|
||||
use App\Models\Outlet;
|
||||
use App\Models\User;
|
||||
use App\Rules\PhoneNumber;
|
||||
use App\Traits\WithMediaHandler;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@ -146,6 +147,9 @@ public function store(): void
|
||||
$this->createOpeningHours($outlet, $data['opening_hours']);
|
||||
$this->createFacilities($outlet, $data['facilities']);
|
||||
$this->handleMediaUpload($outlet);
|
||||
|
||||
// Auto-assign users with Developer, Owner, and Leader roles to the new outlet
|
||||
$this->assignUsersToOutlet($outlet);
|
||||
});
|
||||
}
|
||||
|
||||
@ -190,6 +194,19 @@ private function handleMediaUpload(Outlet $outlet): void
|
||||
$this->uploadMedia($this->images, $outlet, 'images');
|
||||
}
|
||||
|
||||
private function assignUsersToOutlet(Outlet $outlet): void
|
||||
{
|
||||
// Get users with Developer, Owner, and Leader roles
|
||||
$users = User::whereHas('roles', function ($query) {
|
||||
$query->whereIn('name', ['Developer', 'Owner', 'Leader']);
|
||||
})->get();
|
||||
|
||||
// Assign users to the outlet
|
||||
if ($users->isNotEmpty()) {
|
||||
$outlet->users()->attach($users->pluck('id'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user