/** * Remove the specified resource from storage. * * @Delete("user/type/delete/{id}") * @param int $id * @return \Illuminate\Http\Response */ public function destroyType($id) { $usersToDelete = []; $users = User::where('type_id', $id)->get(); //We retrieve all users which have the type that we want to delete foreach ($users as $user) { $usersToDelete[] = $user->id; //We store the users id to delete } User::destroy($usersToDelete); //We delete those users. We need delete them before becouse users have a foreign key (type_id) Type::destroy($id); Session::flash('message', 'Tipo Eliminado Correctamente'); return Redirect::to('/user/type'); }