public function restoreSingleEntity() { try { //Get the entity type and Id $entityType = \Input::get('restoreentitytype'); $entityId = \Input::get('restoreentityid'); if ($entityType == 'tasks') { //Find the task $restoreTask = \Task::withTrashed()->find($entityId); //Get the project Id associated with task $projectId = $restoreTask->project_id; if ($projectId != null) { $project = \Project::withTrashed()->find($projectId); //Check if project is deleted or not if (!$project->trashed()) { //Project is not deleted, restore task $restoreTask->restore(); \Taskcollabs::withTrashed()->where('task_id', $entityId)->restore(); } } else { //No project is associtated, restore task $restoreTask->restore(); \Taskcollabs::withTrashed()->where('task_id', $entityId)->restore(); } $tasks = \Task::onlyTrashed()->get()->toArray(); $data; if (sizeof($tasks) != 0) { foreach ($tasks as $task) { $tempData; $tempData['id'] = $task['id']; $tempData['name'] = $task['name']; $tempData['created_at'] = $task['created_at']; $tempData['deleted_at'] = $task['deleted_at']; $tempData['updated_at'] = $task['updated_at']; $data[] = $tempData; } //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Task Restored'); return \View::make('dashboard.admin.data')->with('data', $data)->with('type', 'Tasks'); } else { //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Task Restored'); return \View::make('dashboard.admin.data')->with('data', null)->with('type', 'Tasks'); } } elseif ($entityType == 'projects') { //List all Task Ids of the project $taskIds = \Task::withTrashed()->where('project_id', $entityId)->lists('id'); if (sizeof($taskIds) != 0) { foreach ($taskIds as $taskId) { $task = \Task::withTrashed()->find($taskId); //Check if task if trashed or not if ($task->trashed()) { //Restore Task $task->restore(); \Taskcollabs::withTrashed()->where('task_id', $taskId)->restore(); } } } //Find Project and restore $project = \Project::withTrashed()->find($entityId); $project->restore(); $projectCollabs = \Projectcollabs::withTrashed()->where('project_id', $entityId)->restore(); $projects = \Project::onlyTrashed()->get()->toArray(); $data; if (sizeof($projects) != 0) { foreach ($projects as $project) { $tempData; $tempData['id'] = $project['id']; $tempData['name'] = $project['project_name']; $tempData['created_at'] = $project['created_at']; $tempData['deleted_at'] = $project['deleted_at']; $tempData['updated_at'] = $project['updated_at']; $data[] = $tempData; } //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Project Restored'); return \View::make('dashboard.admin.data')->with('data', $data)->with('type', 'Projects'); } else { //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Project Restored'); return \View::make('dashboard.admin.data')->with('data', null)->with('type', 'Projects'); } } elseif ($entityType == 'events') { //Find Event and restore it $restoreEvent = \Events::withTrashed()->find($entityId); $restoreEvent->restore(); $restoreEventCollabs = \EventUser::withTrashed()->where('events_id', $entityId)->restore(); $events = \Events::onlyTrashed()->get()->toArray(); $data; if (sizeof($events) != 0) { foreach ($events as $event) { $tempData; $tempData['id'] = $event['id']; $tempData['name'] = $event['title']; $tempData['date'] = $event['date']; $tempData['created_at'] = $event['created_at']; $tempData['deleted_at'] = $event['deleted_at']; $tempData['updated_at'] = $event['updated_at']; $data[] = $tempData; } //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Event Restored'); return \View::make('dashboard.admin.data')->with('data', $data)->with('type', 'Events'); } else { //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Event Restored'); return \View::make('dashboard.admin.data')->with('data', null)->with('type', 'Events'); } } } catch (\Exception $e) { \Log::error('Something Went Wrong in Admin Data Controller - restoreSingleEntity():' . $e->getMessage()); throw new \SomethingWentWrongException(); } }