/** * Remove the specified resource from storage. * DELETE /projects/{id} * * @param int $id * @return Response */ public function destroy($id) { $pTitle = "Projects"; $project = Project::find(Input::get("id")); // delete everything associated with project Task::where('project_id', Input::get("id"))->delete(); Credential::where('project_id', Input::get("id"))->delete(); $project->members()->detach(); // delete the project $project->delete(); $counter = 0; $user = User::find(Auth::id()); $projects = $user->projects()->get(); $inProjects = $user->inProjects()->orderBy('created_at', 'desc')->take(5)->get(); return View::make('projects.index', compact(['projects', 'counter', 'inProjects', 'pTitle'])); }
/** * Remove the specified resource from storage. * DELETE /clients/{id} * * @param int $id * @return Response */ public function destroy($id) { $pTitle = "Clients"; $c_id = Input::get('id'); $client = Client::find($c_id); // delete all related tasks and credentials foreach ($client->projects as $p) { Task::where('project_id', $p->id)->delete(); Credential::where('project_id', $p->id)->delete(); $p->members()->detach(); } // delete related projects Project::where("client_id", $c_id)->delete(); // delete client $client->delete(); // ---------------------------------------------------- $user = User::find(Auth::id()); $clients = $user->clients()->orderBy('created_at', 'desc')->get(); $counter = 0; return View::make('clients.index', compact(['clients', 'counter', 'pTitle'])); }