114 lines
3.9 KiB
PHP
114 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\LandingPage;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\LandingPageCustomPage;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
|
|
class CustomPageController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$query = LandingPageCustomPage::query();
|
|
|
|
// Search functionality
|
|
if ($request->filled('search')) {
|
|
$search = $request->get('search');
|
|
$query->where(function ($q) use ($search) {
|
|
$q->where('title', 'like', "%{$search}%")
|
|
->orWhere('content', 'like', "%{$search}%")
|
|
->orWhere('slug', 'like', "%{$search}%");
|
|
});
|
|
}
|
|
|
|
// Sorting
|
|
$sortField = $request->get('sort_field', 'sort_order');
|
|
$sortDirection = $request->get('sort_direction', 'asc');
|
|
|
|
if (in_array($sortField, ['title', 'created_at', 'sort_order'])) {
|
|
$query->orderBy($sortField, $sortDirection);
|
|
} else {
|
|
$query->ordered();
|
|
}
|
|
|
|
$pages = $query->paginate($request->get('per_page', 10))
|
|
->withQueryString();
|
|
|
|
return Inertia::render('landing-page/custom-pages/index', [
|
|
'pages' => $pages,
|
|
'filters' => $request->only(['search', 'sort_field', 'sort_direction', 'per_page'])
|
|
]);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return Inertia::render('landing-page/custom-pages/create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'title' => 'required|string|max:255|unique:landing_page_custom_pages,title,' . $customPage->id,
|
|
'content' => 'required|string',
|
|
'meta_title' => 'nullable|string|max:255',
|
|
'meta_description' => 'nullable|string',
|
|
'is_active' => 'boolean',
|
|
'sort_order' => 'nullable|integer'
|
|
]);
|
|
|
|
LandingPageCustomPage::create($validated);
|
|
|
|
return redirect()->route('landing-page.custom-pages.index')->with('success', __('Custom page created successfully!'));
|
|
}
|
|
|
|
public function edit(LandingPageCustomPage $customPage)
|
|
{
|
|
return Inertia::render('landing-page/custom-pages/edit', [
|
|
'page' => $customPage
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, LandingPageCustomPage $customPage)
|
|
{
|
|
$validated = $request->validate([
|
|
'title' => 'required|string|max:255|unique:landing_page_custom_pages,title,' . $customPage->id,
|
|
'content' => 'required|string',
|
|
'meta_title' => 'nullable|string|max:255',
|
|
'meta_description' => 'nullable|string',
|
|
'is_active' => 'sometimes|boolean',
|
|
'sort_order' => 'nullable|integer'
|
|
]);
|
|
|
|
// Ensure is_active is properly handled
|
|
if (!isset($validated['is_active'])) {
|
|
$validated['is_active'] = $request->has('is_active') ? (bool)$request->input('is_active') : false;
|
|
}
|
|
|
|
$customPage->update($validated);
|
|
|
|
return redirect()->route('landing-page.custom-pages.index')->with('success', __('Custom page updated successfully!'));
|
|
}
|
|
|
|
public function destroy(LandingPageCustomPage $customPage)
|
|
{
|
|
$customPage->delete();
|
|
return back()->with('success', __('Custom page deleted successfully!'));
|
|
}
|
|
|
|
public function show($slug)
|
|
{
|
|
$page = LandingPageCustomPage::where('slug', $slug)->where('is_active', true)->firstOrFail();
|
|
$landingSettings = \App\Models\LandingPageSetting::getSettings();
|
|
|
|
// Track page visit for super admin analytics
|
|
// \Shetabit\Visitor\Facade\Visitor::visit();
|
|
|
|
return Inertia::render('landing-page/custom-page', [
|
|
'page' => $page,
|
|
'customPages' => LandingPageCustomPage::active()->ordered()->get(),
|
|
'settings' => $landingSettings
|
|
]);
|
|
}
|
|
} |