firstcommit
This commit is contained in:
0
Modules/Page/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Page/app/Http/Controllers/.gitkeep
Normal file
132
Modules/Page/app/Http/Controllers/PageController.php
Normal file
132
Modules/Page/app/Http/Controllers/PageController.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/Page/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Page/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Page/app/Http/Requests/.gitkeep
Normal file
0
Modules/Page/app/Http/Requests/.gitkeep
Normal file
36
Modules/Page/app/Http/Requests/CreatePageRequest.php
Normal file
36
Modules/Page/app/Http/Requests/CreatePageRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreatePageRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:255',
|
||||
'slug' => 'required|string|unique:pages,slug|max:255',
|
||||
'summary' => 'required|string',
|
||||
'description' => 'sometimes|nullable|string',
|
||||
'display_order' => 'sometimes|nullable|integer',
|
||||
'status' => 'required|in:active,inactive',
|
||||
'image' => 'sometimes|nullable|image|mimes:jpeg,png,jpg,gif|max:2048', // Adjust the image rules as needed
|
||||
'meta_title' => 'sometimes|nullable|string|max:255',
|
||||
'meta_description' => 'sometimes|nullable|string|max:255',
|
||||
'meta_keywords' => 'sometimes|nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
// return auth()->user()->can('users.create');
|
||||
}
|
||||
}
|
47
Modules/Page/app/Http/Requests/UpdatePageRequest.php
Normal file
47
Modules/Page/app/Http/Requests/UpdatePageRequest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Http\Requests;
|
||||
|
||||
use Modules\Page\app\Models\Page;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdatePageRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:255',
|
||||
'slug' => 'sometimes|required|string|max:255|unique:pages,slug,' . Page::where('uuid', request('uuid'))->first()->id,
|
||||
// Exclude the current page by ID
|
||||
'summary' => 'sometimes|nullable|string',
|
||||
'description' => 'sometimes|nullable|string',
|
||||
'display_order' => 'sometimes|nullable|integer',
|
||||
'code' => 'sometimes|nullable|string',
|
||||
'status' => 'sometimes|required|in:active,inactive',
|
||||
'image' => 'sometimes|nullable|image|mimes:jpeg,png,jpg,gif|max:2048', // Adjust the image rules as needed
|
||||
'meta_title' => 'sometimes|nullable|string|max:255',
|
||||
'meta_description' => 'sometimes|nullable|string|max:255',
|
||||
'meta_keywords' => 'sometimes|nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
// return auth()->user()->can('users.create');
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'slug.unique' => 'The slug is already in use by another page.',
|
||||
// Add custom error messages for other rules as needed
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user