add: event deletion condition

- One cannot delete an event where users have already claimed a prize. Foreign key constraint stops this. So we implement a condition to prevent this and return message to mark the event as inactive instead.
This commit is contained in:
HDVinnie
2025-05-05 20:26:27 -04:00
parent 89f8afd636
commit 299d1dae2a
@@ -64,6 +64,11 @@ class EventController extends Controller
*/
public function destroy(Event $event): \Illuminate\Http\RedirectResponse
{
if ($event->claimedPrizes()->exists()) {
return redirect()->route('staff.events.index')
->withErrors('Cannot delete event because users have claimed prizes. You can mark it as inactive instead.');
}
$event->delete();
return to_route('staff.events.index');