/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { //Versione semplice $router->model('partecipanti', \App\Partecipante::class); // se devo mettere filtri anche su campi diversi da id $router->bind('partecipanti', function ($id) { return \App\Partecipante::where('id', $id)->firstOrFail(); }); parent::boot($router); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Request $request, Partecipante $partecipante) { $partecipante->delete(); if ($request->ajax() || $request->wantsJson()) { return new JsonResponse($partecipante); } return redirect('partecipanti'); }