singleloginsystem/app/Concerns/HandlesOperations.php
= c0086ddb6a feature: implement ConnectedApp management with creation and editing support
- Added `ConnectedAppData` DTO for structured data representation.
- Implemented Livewire components for ConnectedApp list (`index`) and edit (`edit`).
- Integrated `ConnectedAppService` with CRUD operations.
- Updated routing to include ConnectedApp management paths.
- Enhanced UI with reusable components and dynamic dropdowns for protocols, providers, and statuses.
2026-05-14 14:03:53 +00:00

44 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Concerns;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException;
use Mary\Traits\Toast;
use Throwable;
trait HandlesOperations
{
use Toast;
public function attempt(callable $action, ?callable $onError = null, string $successMessage = 'Success !', string $errorMessage = 'Something gone wrong!', bool $showSuccess = true): void
{
try {
// call the action callback
$action();
if ($showSuccess) {
$this->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());
}
}
}