1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Larafolio\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Larafolio\Models\Page; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Larafolio\Models\Project; |
8
|
|
|
use Larafolio\Models\UserTraits\updatePageOrder; |
9
|
|
|
|
10
|
|
|
class PortfolioController extends Controller |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Show the manager dashboard. |
14
|
|
|
* |
15
|
|
|
* @return \Illuminate\Http\Response |
16
|
|
|
*/ |
17
|
|
|
public function index() |
18
|
|
|
{ |
19
|
|
|
$projects = Project::all()->sortBy('order')->values(); |
20
|
|
|
|
21
|
|
|
$projectImages = $projects->mapWithKeys(function (Project $project) { |
22
|
|
|
return [$project->name() => $project->getProjectImageUrl()]; |
23
|
|
|
})->objectIfEmpty(); |
24
|
|
|
|
25
|
|
|
$projectBlocks = $projects->mapWithKeys(function (Project $project) { |
26
|
|
|
return [$project->name() => $project->getProjectBlockText()]; |
27
|
|
|
})->objectIfEmpty(); |
28
|
|
|
|
29
|
|
|
$pages = Page::all()->sortBy('order')->values(); |
30
|
|
|
|
31
|
|
|
return view('larafolio::projects.index', [ |
32
|
|
|
'projects' => $projects, |
33
|
|
|
'projectImages' => $projectImages, |
34
|
|
|
'projectBlocks' => $projectBlocks, |
35
|
|
|
'pages' => $pages, |
36
|
|
|
'icons' => $this->dashboardIcons(), |
37
|
|
|
]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Update project order in portfolio. |
42
|
|
|
* |
43
|
|
|
* @param Request $request Request data containing all projects. |
44
|
|
|
* |
45
|
|
|
* @return \Illuminate\Http\Response |
46
|
|
|
*/ |
47
|
|
|
public function update(Request $request) |
48
|
|
|
{ |
49
|
|
|
if ($request->has('projects')) { |
50
|
|
|
$updated = $this->user->updateProjectOrder($request->get('projects')); |
51
|
|
|
} else if ($request->has('pages')) { |
52
|
|
|
$updated = $this->user->updatePageOrder($request->get('pages')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return response()->json($updated); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Icons needed for dashboard. |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
protected function dashboardIcons() |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
|
|
'down' => file_get_contents(public_path('vendor/larafolio/zondicons/arrow-thin-down.svg')), |
67
|
|
|
'up' => file_get_contents(public_path('vendor/larafolio/zondicons/arrow-thin-up.svg')), |
68
|
|
|
'hidden' => file_get_contents(public_path('vendor/larafolio/zondicons/view-hide.svg')), |
69
|
|
|
'visible' => file_get_contents(public_path('vendor/larafolio/zondicons/view-show.svg')) |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: