|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Torralbodavid\DuckFunkCore\Http\Controllers\Housekeeping; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Routing\Controller; |
|
7
|
|
|
use Torralbodavid\DuckFunkCore\Http\Request\Housekeeping\News\NewsStoreRequest; |
|
8
|
|
|
use Torralbodavid\DuckFunkCore\Http\Resources\Marketing\NewsResource; |
|
9
|
|
|
use Torralbodavid\DuckFunkCore\Models\Arcturus\Permissions; |
|
10
|
|
|
use Torralbodavid\DuckFunkCore\Models\CMS\Page; |
|
11
|
|
|
use Torralbodavid\DuckFunkCore\Models\Housekeeping\News; |
|
12
|
|
|
|
|
13
|
|
|
class PageController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Display a listing of the resource. |
|
17
|
|
|
* |
|
18
|
|
|
* @return \Illuminate\Http\Response |
|
19
|
|
|
*/ |
|
20
|
|
|
public function index() |
|
21
|
|
|
{ |
|
22
|
|
|
// |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Show the form for creating a new resource. |
|
27
|
|
|
* |
|
28
|
|
|
* @return \Illuminate\Http\Response |
|
29
|
|
|
*/ |
|
30
|
|
|
public function create() |
|
31
|
|
|
{ |
|
32
|
|
|
$data = [ |
|
33
|
|
|
'permissions' => Permissions::all(), |
|
34
|
|
|
'pages' => Page::where('active', true)->get(), |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
return response()->view('housekeeping::pages.edit', $data, 200); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Store a newly created resource in storage. |
|
42
|
|
|
* |
|
43
|
|
|
* @param NewsStoreRequest $request |
|
44
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
45
|
|
|
*/ |
|
46
|
|
|
public function store(NewsStoreRequest $request) |
|
47
|
|
|
{ |
|
48
|
|
|
$validated = $request->validated(); |
|
49
|
|
|
|
|
50
|
|
|
$news = Page::firstOrCreate( |
|
51
|
|
|
[ |
|
52
|
|
|
'slug' => $validated['slug'], |
|
53
|
|
|
'route' => $validated['route'], |
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
|
|
$news->categories = $validated['allCategories']; |
|
57
|
|
|
$news->draft = 0; |
|
58
|
|
|
|
|
59
|
|
|
try { |
|
60
|
|
|
$news->saveOrFail(); |
|
61
|
|
|
} catch (\Throwable $e) { |
|
62
|
|
|
return response()->json([ |
|
|
|
|
|
|
63
|
|
|
'message' => "Ha sucedido un error {$e->getMessage()}", |
|
64
|
|
|
'error' => true, |
|
65
|
|
|
]); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return response()->json([ |
|
69
|
|
|
'message' => 'Página publicada correctamente', |
|
70
|
|
|
'error' => false, |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Display the specified resource. |
|
76
|
|
|
* |
|
77
|
|
|
* @param int $id |
|
78
|
|
|
* @return \Illuminate\Http\Response |
|
79
|
|
|
*/ |
|
80
|
|
|
public function show($id) |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
// |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Show the form for editing the specified resource. |
|
87
|
|
|
* |
|
88
|
|
|
* @param News $news |
|
89
|
|
|
* @return \Illuminate\Http\Response |
|
90
|
|
|
*/ |
|
91
|
|
|
public function edit(News $news) |
|
92
|
|
|
{ |
|
93
|
|
|
$data = [ |
|
94
|
|
|
'news' => new NewsResource($news), |
|
95
|
|
|
]; |
|
96
|
|
|
|
|
97
|
|
|
return view('housekeeping::pages.edit', $data); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Update the specified resource in storage. |
|
102
|
|
|
* |
|
103
|
|
|
* @param \Illuminate\Http\Request $request |
|
104
|
|
|
* @param int $id |
|
105
|
|
|
* @return \Illuminate\Http\Response |
|
106
|
|
|
*/ |
|
107
|
|
|
public function update(Request $request, $id) |
|
|
|
|
|
|
108
|
|
|
{ |
|
109
|
|
|
// |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Remove the specified resource from storage. |
|
114
|
|
|
* |
|
115
|
|
|
* @param int $id |
|
116
|
|
|
* @return \Illuminate\Http\Response |
|
117
|
|
|
*/ |
|
118
|
|
|
public function destroy($id) |
|
|
|
|
|
|
119
|
|
|
{ |
|
120
|
|
|
// |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: