'phosphor-mountains', 'label' => 'Mountains'], ['component' => 'phosphor-compass', 'label' => 'Compass'], ['component' => 'phosphor-tent', 'label' => 'Tent'], ['component' => 'phosphor-map-trifold', 'label' => 'Map'], ['component' => 'phosphor-footprints', 'label' => 'Footprints'], ['component' => 'phosphor-fire', 'label' => 'Fire'], ['component' => 'phosphor-star', 'label' => 'Star'], ['component' => 'phosphor-flag', 'label' => 'Flag'], ['component' => 'phosphor-trophy', 'label' => 'Trophy'], ['component' => 'phosphor-target', 'label' => 'Target'], ['component' => 'solar-sun-linear', 'label' => 'Sun'], ['component' => 'solar-moon-linear', 'label' => 'Moon'], ['component' => 'bi-heart', 'label' => 'Heart'], ]; public function openModal(): void { $this->resetValidation(); $this->isOpen = true; } public function closeModal(): void { $this->isOpen = false; $this->avatarModalOpen = false; } public function openAvatarModal(): void { $this->resetValidation(); $this->avatarModalOpen = true; } public function closeAvatarModal(): void { $this->avatarModalOpen = false; } public function setAvatarTab(string $tab): void { if (!in_array($tab, ['icon', 'photo'], true)) { return; } $this->avatarTab = $tab; $this->resetValidation(); } public function selectIcon(string $component): void { $allowed = array_column($this->icons, 'component'); if (!in_array($component, $allowed, true)) { return; } $this->avatarIcon = $component; $this->avatarPhoto = null; $this->avatarTab = 'icon'; } public function updatedAvatarPhoto(): void { if ($this->avatarPhoto) { $this->avatarIcon = null; $this->avatarTab = 'photo'; } } #[Computed] public function filteredIcons(): array { $q = trim(mb_strtolower($this->iconSearch)); if ($q === '') { return $this->icons; } return array_values(array_filter($this->icons, function (array $icon) use ($q) { return str_contains(mb_strtolower($icon['label']), $q) || str_contains(mb_strtolower($icon['component']), $q); })); } #[Computed] public function avatarPreviewType(): string { if ($this->avatarPhoto) { return 'photo'; } if ($this->avatarIcon) { return 'icon'; } return 'none'; } public function save() { $this->validate([ 'name' => ['required', 'string', 'max:60'], 'description' => ['nullable', 'string', 'max:140'], 'avatarIcon' => ['nullable', 'string', 'max:100'], 'avatarPhoto' => ['nullable', 'image', 'max:4096'], ]); $crew = Crew::create([ 'name' => $this->name, 'description' => $this->description ?: null, 'avatar_icon' => $this->avatarIcon, 'image_id' => null, 'cover_image_id' => null, ]); if ($this->avatarPhoto) { $disk = 'public'; $ext = $this->avatarPhoto->getClientOriginalExtension(); $ext = $ext ? mb_strtolower($ext) : 'jpg'; $path = "crews/{$crew->id}/avatar.{$ext}"; Storage::disk($disk)->putFileAs( "crews/{$crew->id}", $this->avatarPhoto, "avatar.{$ext}" ); $absolute = Storage::disk($disk)->path($path); $width = null; $height = null; $sizeData = @getimagesize($absolute); if (is_array($sizeData)) { $width = $sizeData[0] ?? null; $height = $sizeData[1] ?? null; } $image = Image::create([ 'disk' => $disk, 'bucket' => null, 'path' => $path, 'original_name' => $this->avatarPhoto->getClientOriginalName(), 'mime_type' => $this->avatarPhoto->getMimeType(), 'size' => $this->avatarPhoto->getSize(), 'width' => $width, 'height' => $height, 'variants' => null, 'visibility' => 'public', 'checksum' => null, 'exif_stripped' => true, 'uploaded_by_user_id' => Auth::id(), ]); $crew->image_id = $image->id; $crew->save(); } $crew->users()->attach(Auth::id()); // ToastMagic success $this->dispatch('toastmagic', type: 'success', message: 'Group created'); return redirect('/groups'); } }; ?>
@if($isOpen) @endif