1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use App\Http\Requests\Admin\CreateUpdateProject; |
7
|
|
|
use App\Project; |
8
|
|
|
|
9
|
|
|
class ProjectController extends Controller |
10
|
|
|
{ |
11
|
|
|
public function create(CreateUpdateProject $request) |
12
|
|
|
{ |
13
|
|
|
$project = new Project(); |
14
|
|
|
$project->name = $request->name; |
15
|
|
|
$project->description = $request->description; |
16
|
|
|
$project->save(); |
17
|
|
|
return redirect()->route('admin.events.dashboard') |
18
|
|
|
->with('status', 'Created Project successfully!'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function get(Project $project) |
22
|
|
|
{ |
23
|
|
|
return view('admin.events.manage-project', [ |
24
|
|
|
'project' => $project |
25
|
|
|
]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function update(Project $project, CreateUpdateProject $request) |
29
|
|
|
{ |
30
|
|
|
$project->name = $request->name; |
31
|
|
|
$project->description = $request->description; |
32
|
|
|
$project->save(); |
33
|
|
|
return redirect()->route('admin.events.dashboard') |
34
|
|
|
->with('status', 'Updated Project successfully!'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function delete(Project $project) |
38
|
|
|
{ |
39
|
|
|
// check if events are associate with the to be deleted project |
40
|
|
|
// if yes do not delete and send back with errors |
41
|
|
|
if( $project->events()->exists() ) |
42
|
|
|
{ |
43
|
|
|
return redirect()->route('admin.events.project.get', $project) |
44
|
|
|
->with('status', 'Error on deletion: Project has events!'); |
45
|
|
|
} |
46
|
|
|
$project->delete(); |
47
|
|
|
return redirect()->route('admin.events.dashboard') |
48
|
|
|
->with('status', 'Deleted Project successfully!'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function archive(Project $project) |
52
|
|
|
{ |
53
|
|
|
$project->is_archived = true; |
54
|
|
|
$project->save(); |
55
|
|
|
return redirect()->route('admin.events.dashboard') |
56
|
|
|
->with('status', 'Archived successfully!'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function restore(Project $project) |
60
|
|
|
{ |
61
|
|
|
$project->is_archived = false; |
62
|
|
|
$project->save(); |
63
|
|
|
return redirect()->route('admin.events.dashboard') |
64
|
|
|
->with('status', 'Restored successfully!'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|