1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Larafolio\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Larafolio\Models\Project; |
7
|
|
|
use Larafolio\Http\Requests\AddProjectRequest; |
8
|
|
|
|
9
|
|
|
class ProjectController extends Controller |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Return all projects. |
13
|
|
|
* |
14
|
|
|
* @return \Illuminate\Http\JsonResponse |
15
|
|
|
*/ |
16
|
|
|
public function index() |
17
|
|
|
{ |
18
|
|
|
return response()->json(Project::all()); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Show an individual project in the manager. |
23
|
|
|
* |
24
|
|
|
* @param string $slug Slug of the project to show. |
25
|
|
|
* |
26
|
|
|
* @return \Illuminate\Http\Response |
27
|
|
|
*/ |
28
|
|
|
public function show($slug) |
29
|
|
|
{ |
30
|
|
|
$project = Project::withBlocks($slug)->first(); |
31
|
|
|
|
32
|
|
|
if (!$project) { |
33
|
|
|
abort(404, "No project with slug {$slug} found."); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$images = $project->imagesWithProps(); |
37
|
|
|
|
38
|
|
|
return view('larafolio::projects.show', [ |
39
|
|
|
'project' => $project, |
40
|
|
|
'images' => $images, |
41
|
|
|
]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Return the project create page. |
46
|
|
|
* |
47
|
|
|
* @return \Illuminate\Http\Response |
48
|
|
|
*/ |
49
|
|
|
public function create() |
50
|
|
|
{ |
51
|
|
|
return view('larafolio::projects.add'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Add a new project to the portfolio. |
56
|
|
|
* |
57
|
|
|
* @param AddProjectRequest $request Form request. |
58
|
|
|
* |
59
|
|
|
* @return \Illuminate\Http\Response |
60
|
|
|
*/ |
61
|
|
|
public function store(AddProjectRequest $request) |
62
|
|
|
{ |
63
|
|
|
$project = $this->user->addProject($request->all()); |
64
|
|
|
|
65
|
|
|
if ($request->ajax()) { |
66
|
|
|
return response()->json(['project' => $project]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return redirect(route('show-project', ['project' => $project])); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Return the project edit form view. |
74
|
|
|
* |
75
|
|
|
* @param string $slug Slug for the project to edit. |
76
|
|
|
* |
77
|
|
|
* @return \Illuminate\Http\Response |
78
|
|
|
*/ |
79
|
|
|
public function edit($slug) |
80
|
|
|
{ |
81
|
|
|
$project = Project::full($slug)->first(); |
82
|
|
|
|
83
|
|
|
$nextBlock = $project->blocks->pluck('order')->max() + 1; |
84
|
|
|
|
85
|
|
|
$nextLink = $project->links->pluck('order')->max() + 1; |
86
|
|
|
|
87
|
|
|
return view('larafolio::projects.edit', [ |
88
|
|
|
'project' => $project, |
89
|
|
|
'nextBlock' => $nextBlock, |
90
|
|
|
'nextLink' => $nextLink, |
91
|
|
|
]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Update a project. |
96
|
|
|
* |
97
|
|
|
* @param \Illuminate\Http\Request $request Request data. |
98
|
|
|
* @param string $slug Slug of project to update. |
99
|
|
|
* |
100
|
|
|
* @return \Illuminate\Http\Response |
101
|
|
|
*/ |
102
|
|
|
public function update(Request $request, $slug) |
103
|
|
|
{ |
104
|
|
|
$project = Project::withTrashed()->where('slug', $slug)->first(); |
105
|
|
|
|
106
|
|
|
if ($project->trashed()) { |
107
|
|
|
$this->user->restoreProject($project); |
108
|
|
|
} else { |
109
|
|
|
$this->user->updateProject($project, $request->all()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
if ($request->ajax()) { |
113
|
|
|
return response()->json(['project' => $project]); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return redirect(route('show-project', ['project' => $project])); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Remove a project from the portfolio. |
121
|
|
|
* |
122
|
|
|
* @param \Illuminate\Http\Request $request Request data. |
123
|
|
|
* @param string $slug Slug of project to remove. |
124
|
|
|
* |
125
|
|
|
* @return \Illuminate\Http\Response |
126
|
|
|
*/ |
127
|
|
|
public function destroy(Request $request, $slug) |
128
|
|
|
{ |
129
|
|
|
$project = Project::withTrashed()->where('slug', $slug)->first(); |
130
|
|
|
|
131
|
|
|
if ($project->trashed()) { |
132
|
|
|
$this->user->purgeProject($project); |
133
|
|
|
} else { |
134
|
|
|
$this->user->removeProject($project); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if ($request->ajax()) { |
138
|
|
|
return response()->json(true); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return redirect(route('dashboard')); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: