Skip to content

Commit

Permalink
custom item actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Oct 7, 2022
1 parent e82849d commit e4855d9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Http/Controllers/MoonShineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Leeto\MoonShine\Http\Controllers;

use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Routing\ResponseFactory;
Expand Down Expand Up @@ -44,7 +45,14 @@ public function action($id, $index): RedirectResponse

abort_if(!$action = $this->resource->itemActions()[$index] ?? false, 404);

$action->callback($item);
try {
$action->callback($item);
} catch (Exception $e) {
throw_if(!app()->isProduction(), $e);

return back()
->with('alert', trans('moonshine::ui.saved_error'));
}

return back()
->with('alert', $action->message());
Expand Down

0 comments on commit e4855d9

Please sign in to comment.