1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Project; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
|
8
|
|
|
class ProjectsController extends Controller |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Instantiate a new ProjectsController |
12
|
|
|
*/ |
13
|
|
|
public function __construct() |
14
|
|
|
{ |
15
|
|
|
$this->middleware('auth'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Display a list of the currently authenticated users projects |
20
|
|
|
* |
21
|
|
|
* @return \Illuminate\View\View |
22
|
|
|
*/ |
23
|
|
|
public function index() |
24
|
|
|
{ |
25
|
|
|
$this->seo()->setTitle('My Projects'); |
26
|
|
|
$this->seo()->setDescription('Here is where you can access all of your projects to log time, create milestones etc.'); |
27
|
|
|
|
28
|
|
|
$projects = auth()->user()->projects; |
29
|
|
|
|
30
|
|
|
return view('home', compact('projects')); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Show a single project |
35
|
|
|
* |
36
|
|
|
* @param \App\Project $project |
37
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View |
38
|
|
|
*/ |
39
|
|
|
public function show(Project $project) |
40
|
|
|
{ |
41
|
|
|
if (!auth()->user()->can('view', $project)) { |
42
|
|
|
return redirect()->route('home'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->seo()->setTitle($project->title); |
46
|
|
|
$this->seo()->setDescription($project->description); |
47
|
|
|
|
48
|
|
|
return view('projects.show', compact('project')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Display the create project form |
53
|
|
|
* |
54
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View |
55
|
|
|
*/ |
56
|
|
|
public function create() |
57
|
|
|
{ |
58
|
|
|
$this->seo()->setTitle('Create Project'); |
59
|
|
|
$this->seo()->setDescription('Once your project is created, you can log time against it, add milestones, and see how much time you have left.'); |
60
|
|
|
|
61
|
|
|
return view('projects.create'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Store a new project in the database |
66
|
|
|
* |
67
|
|
|
* @param Request $request |
68
|
|
|
* @return \Illuminate\Http\RedirectResponse |
69
|
|
|
*/ |
70
|
|
|
public function store(Request $request) |
71
|
|
|
{ |
72
|
|
|
$request->validate([ |
73
|
|
|
'title' => 'required', |
74
|
|
|
'description' => 'required|min:4', |
75
|
|
|
'total_seconds' => 'required|integer|min:0' |
76
|
|
|
]); |
77
|
|
|
|
78
|
|
|
$project = auth()->user()->projects()->create($request->all()); |
79
|
|
|
|
80
|
|
|
return redirect()->route('projects.show', [$project]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Edit a Project |
85
|
|
|
* |
86
|
|
|
* @param \App\Project $project |
87
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View |
88
|
|
|
*/ |
89
|
|
|
public function edit(Project $project) |
90
|
|
|
{ |
91
|
|
|
if (!auth()->user()->can('update', $project)) { |
92
|
|
|
return redirect()->route('home'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$this->seo()->setTitle('Update Project: '. $project->title); |
96
|
|
|
$this->seo()->setDescription($project->description); |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
return view('projects.edit', compact('project')); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Update a project |
104
|
|
|
* |
105
|
|
|
* @param \Illuminate\Http\Request $request |
106
|
|
|
* @param \App\Project $project |
107
|
|
|
* @return \Illuminate\Http\RedirectResponse |
108
|
|
|
*/ |
109
|
|
|
public function update(Request $request, Project $project) |
110
|
|
|
{ |
111
|
|
|
if (!auth()->user()->can('update', $project)) { |
112
|
|
|
return redirect()->route('home'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$request->validate([ |
116
|
|
|
'title' => 'required', |
117
|
|
|
'description' => 'required|min:4', |
118
|
|
|
'total_seconds' => 'required|integer|min:0' |
119
|
|
|
]); |
120
|
|
|
|
121
|
|
|
$project->update($request->all()); |
122
|
|
|
|
123
|
|
|
return redirect()->to($project->url()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Delete a project |
128
|
|
|
* |
129
|
|
|
* @param \App\Project $project |
130
|
|
|
* @return \Illuminate\Http\RedirectResponse |
131
|
|
|
*/ |
132
|
|
|
public function destroy(Project $project) |
133
|
|
|
{ |
134
|
|
|
if (!auth()->user()->can('delete', $project)) { |
135
|
|
|
return redirect()->route('home'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$project->delete(); |
139
|
|
|
|
140
|
|
|
return redirect()->route('projects.index'); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|