133 lines
3.3 KiB
PHP
133 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Page\app\Http\Controllers;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Modules\Page\app\Models\Page;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Modules\Page\app\Models\PageMeta;
|
|
use Modules\Page\app\Repositories\PageRepository;
|
|
use Modules\Page\app\Services\FileManagementService;
|
|
use Modules\Page\app\Http\Requests\CreatePageRequest;
|
|
use Modules\Page\app\Http\Requests\UpdatePageRequest;
|
|
|
|
class PageController extends Controller
|
|
{
|
|
protected $pageRepository;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->pageRepository = new PageRepository;
|
|
}
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$pages = $this->pageRepository->allPages();
|
|
return view('page::index', compact('pages'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('page::create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(CreatePageRequest $request): RedirectResponse
|
|
{
|
|
try {
|
|
$validated = $request->validated();
|
|
$this->pageRepository->storePage($validated);
|
|
|
|
toastr()->success('Page created successfully.');
|
|
|
|
return redirect()->route('cms.pages.index');
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
toastr()->error('Something went wrong.');
|
|
return back();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*/
|
|
public function show($id)
|
|
{
|
|
return view('page::show');
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($uuid)
|
|
{
|
|
$page = $this->pageRepository->findPageByUuid($uuid);
|
|
|
|
if (! $page) {
|
|
toastr()->error('Page not found.');
|
|
return back();
|
|
}
|
|
return view('page::edit', compact('page'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(UpdatePageRequest $request, $uuid): RedirectResponse
|
|
{
|
|
try {
|
|
$validated = $request->validated();
|
|
|
|
$page = $this->pageRepository->updatePage($validated, $uuid);
|
|
|
|
if (! $page) {
|
|
toastr()->error('Page not found !');
|
|
return back();
|
|
}
|
|
|
|
toastr()->success('Page updated successfully.');
|
|
|
|
return redirect()->route('cms.pages.index');
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
toastr()->error('Something went wrong.');
|
|
return back();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($uuid)
|
|
{
|
|
try {
|
|
$page = $this->pageRepository->deletePage($uuid);
|
|
|
|
if (! $page) {
|
|
toastr()->error('Page not found.');
|
|
return back();
|
|
}
|
|
DB::commit();
|
|
toastr()->success('Page deleted successfully.');
|
|
|
|
return redirect()->route('cms.pages.index');
|
|
} catch (\Throwable $th) {
|
|
DB::rollback();
|
|
report($th);
|
|
toastr()->error('Something went wrong.');
|
|
return back();
|
|
}
|
|
}
|
|
}
|