diff --git a/app/Livewire/Forms/Studio/Master/OutletForm.php b/app/Livewire/Forms/Studio/Master/OutletForm.php index 5f887ca..cfa64a8 100644 --- a/app/Livewire/Forms/Studio/Master/OutletForm.php +++ b/app/Livewire/Forms/Studio/Master/OutletForm.php @@ -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();