-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathPageController.php
More file actions
117 lines (94 loc) · 3.27 KB
/
Copy pathPageController.php
File metadata and controls
117 lines (94 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Admin;
use App\Concerns\PagesSecondaryNavigation;
use App\Contracts\HasSecondaryNavigation;
use App\Http\Requests\Admin\PageRequest;
use App\Http\Resources\Collections\PageCollection;
use App\Http\Resources\PageResource;
use App\Models\Page;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Inertia\Response;
class PageController extends AdminController implements HasSecondaryNavigation
{
use PagesSecondaryNavigation;
public function index(): Response
{
return Inertia::render('Pages/Index', [
'collection' => new PageCollection(
Page::query()
->withDrafted()
->sort(
defaultColumn: 'created_at',
defaultDirection: 'desc'
)
->filter()
->paginate()
),
'subnav' => $this->getSecondaryNavigation(),
]);
}
public function create(): Response
{
return Inertia::render('Pages/Edit', [
'pages' => Page::query()
->withDrafted()
->orderByTranslated('title')
->get(['id', 'title']),
])->model(Page::class);
}
public function store(PageRequest $request): RedirectResponse
{
$attributes = $request->validated();
$page = Page::create($attributes);
$page->saveBlocks($attributes['blocks'])
->saveMedia($attributes['media']);
return redirect()->route('admin.pages.edit', $page)
->with('success', __('page.event.created'));
}
public function edit(Page $page): Response
{
return Inertia::render('Pages/Edit', [
'resource' => PageResource::make($page),
'pages' => Page::query()
->withDrafted()
->orderByTranslated('title')
->whereNotDescendantOf($page->id)
->get(['id', 'title']),
])->model(Page::class);
}
public function update(PageRequest $request, Page $page): RedirectResponse
{
$attributes = $request->validated();
$page->update($attributes);
$page->saveBlocks($attributes['blocks'])
->saveMedia($attributes['media']);
return redirect()->route('admin.pages.edit', $page)
->with('success', __('page.event.updated'));
}
public function duplicate(Page $page): RedirectResponse
{
$duplicate = $page->duplicate();
return redirect()->route('admin.pages.edit', $duplicate)
->with('success', __('page.event.duplicated'));
}
public function destroy(Page $page): RedirectResponse
{
$page->delete();
return redirect()->route('admin.pages.index')
->with('success', __('page.event.deleted'));
}
public function restore(Page $page): RedirectResponse
{
$page->restore();
return redirect()->route('admin.pages.edit', $page)
->with('success', __('page.event.restored'));
}
public function forceDelete(Page $page): RedirectResponse
{
$page->forceDelete();
return redirect()->route('admin.pages.index')
->with('success', __('page.event.deleted'));
}
}