- Introduced `HandlesOperations` trait for reusable error handling with toasts and logging. - Added `StoreConnectionProviderForm` Livewire component with validation and slug uniqueness check. - Implemented `StoreConnectionProviderRequestData` DTO for structured data handling. - Updated `ConnectionProviderService` to include `create()` method using database transactions. - Registered new routes for creating connection providers. - Enhanced `ConnectionProvider` model with `Fillable` attribute for `name` and `slug`.
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Livewire\Forms;
|
|
|
|
use App\Data\ConnectedApp\StoreConnectionProviderRequestData;
|
|
use App\Models\ConnectionProvider;
|
|
use App\Services\ConnectionProviderService;
|
|
use Closure;
|
|
use Illuminate\Support\Str;
|
|
use Livewire\Form;
|
|
|
|
class StoreConnectionProviderForm extends Form
|
|
{
|
|
public string $name = '';
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => [
|
|
'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);
|
|
}
|
|
}
|