diff --git a/app/Concerns/HandlesOperations.php b/app/Concerns/HandlesOperations.php new file mode 100644 index 0000000..e41dc1e --- /dev/null +++ b/app/Concerns/HandlesOperations.php @@ -0,0 +1,42 @@ +success($successMessage); + } catch (ValidationException $exception) { + + /** + * We are catching this exception intentionally so that, generic throwable catch block + * doesn't catch this, which will lead to close the modal. + * + * But, we are rethrowing this so that validation errors can be handled by others. + */ + + throw $exception; + } catch (Throwable $exception) { + if (null !== $onError) { + // call the callback + $onError(); + } + $this->error($errorMessage); + Log::error($exception->getMessage()); + Log::error($exception->getTraceAsString()); + } + } +} diff --git a/app/Data/ConnectedApp/StoreConnectionProviderRequestData.php b/app/Data/ConnectedApp/StoreConnectionProviderRequestData.php new file mode 100644 index 0000000..d3c564f --- /dev/null +++ b/app/Data/ConnectedApp/StoreConnectionProviderRequestData.php @@ -0,0 +1,21 @@ +slug = str($name)->slug()->toString(); + } +} diff --git a/app/Livewire/Forms/StoreConnectionProviderForm.php b/app/Livewire/Forms/StoreConnectionProviderForm.php new file mode 100644 index 0000000..e0c0139 --- /dev/null +++ b/app/Livewire/Forms/StoreConnectionProviderForm.php @@ -0,0 +1,52 @@ + [ + 'required', + 'string', + 'min:3', + 'max:255', + // Custom Closure to check the generated slug + function (string $attribute, mixed $value, Closure $fail): void { + $slug = Str::slug($value); + + // Check if the slug already exists in your database table + $exists = ConnectionProvider::query() + ->where('slug', $slug) + ->exists(); + + if ($exists) { + $fail("The name '{$value}' is already taken. Please choose a different name."); + } + }, + ], + ]; + } + + public function save(): void + { + $this->validate(); + $service = app(ConnectionProviderService::class); + $data = new StoreConnectionProviderRequestData( + name: $this->name, + ); + $service->create($data); + } +} diff --git a/app/Models/ConnectionProvider.php b/app/Models/ConnectionProvider.php index 16f490a..8740015 100644 --- a/app/Models/ConnectionProvider.php +++ b/app/Models/ConnectionProvider.php @@ -4,6 +4,8 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Model; +#[Fillable(['name', 'slug'])] final class ConnectionProvider extends Model {} diff --git a/app/Services/ConnectionProviderService.php b/app/Services/ConnectionProviderService.php index 3e7412a..e1ee03f 100644 --- a/app/Services/ConnectionProviderService.php +++ b/app/Services/ConnectionProviderService.php @@ -4,11 +4,20 @@ namespace App\Services; +use App\Data\ConnectedApp\StoreConnectionProviderRequestData; use App\Models\ConnectionProvider; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\DB; class ConnectionProviderService { + public function create(StoreConnectionProviderRequestData $requestData): void + { + DB::transaction(function () use ($requestData): void { + ConnectionProvider::query()->create($requestData->toArray()); + }); + } + /** * @return Collection */ diff --git a/resources/views/pages/connecton-providers/⚡create.blade.php b/resources/views/pages/connecton-providers/⚡create.blade.php new file mode 100644 index 0000000..46b7018 --- /dev/null +++ b/resources/views/pages/connecton-providers/⚡create.blade.php @@ -0,0 +1,39 @@ +attempt( + action: function () { + $this->form->save(); + $this->redirectRoute('dashboard', navigate: true); + } + ); + } +}; +?> + +
+ + + + + + + + +
diff --git a/routes/web.php b/routes/web.php index d654c8f..6365b45 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,6 +12,10 @@ Route::prefix('connected-apps')->name('connected-apps.')->group(function (): void { Route::livewire('create', 'pages::connected-apps.create')->name('create'); }); + + Route::prefix('connection-providers')->name('users.')->group(function (): void { + Route::livewire('create', 'pages::connecton-providers.create')->name('create'); + }); }); require __DIR__.'/settings.php';