feat: complete admin CMS for customizable layout, texts, products, categories and orders
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ContentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the layout and texts editor.
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
return view('admin.content.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save updated settings and layout options.
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$fields = [
|
||||
// Brand & Theme
|
||||
'site_name',
|
||||
'site_tagline',
|
||||
'meta_description',
|
||||
'theme_palette',
|
||||
|
||||
// Announcement
|
||||
'announcement_enabled',
|
||||
'announcement_text',
|
||||
'announcement_badge_1',
|
||||
'announcement_badge_2',
|
||||
|
||||
// Hero
|
||||
'hero_badge',
|
||||
'hero_title',
|
||||
'hero_subtitle',
|
||||
'hero_primary_btn_text',
|
||||
'hero_primary_btn_url',
|
||||
'hero_secondary_btn_text',
|
||||
'hero_secondary_btn_url',
|
||||
'hero_stat_1_val',
|
||||
'hero_stat_1_lbl',
|
||||
'hero_stat_2_val',
|
||||
'hero_stat_2_lbl',
|
||||
'hero_stat_3_val',
|
||||
'hero_stat_3_lbl',
|
||||
'hero_card_badge',
|
||||
|
||||
// Categories Section
|
||||
'categories_tag',
|
||||
'categories_title',
|
||||
'categories_subtitle',
|
||||
|
||||
// Featured Products Section
|
||||
'featured_tag',
|
||||
'featured_title',
|
||||
'featured_subtitle',
|
||||
|
||||
// USP / Quality Section
|
||||
'usp_tag',
|
||||
'usp_title',
|
||||
'usp_subtitle',
|
||||
'usp_1_title',
|
||||
'usp_1_desc',
|
||||
'usp_2_title',
|
||||
'usp_2_desc',
|
||||
'usp_3_title',
|
||||
'usp_3_desc',
|
||||
'usp_4_title',
|
||||
'usp_4_desc',
|
||||
'usp_btn_text',
|
||||
|
||||
// Footer
|
||||
'footer_description',
|
||||
'footer_status_text',
|
||||
'footer_email',
|
||||
'footer_shipping_text',
|
||||
'footer_copyright',
|
||||
'footer_payment_text',
|
||||
];
|
||||
|
||||
// Handle checkbox toggles that aren't present if unchecked
|
||||
if (! $request->has('announcement_enabled')) {
|
||||
Setting::set('announcement_enabled', '0');
|
||||
}
|
||||
|
||||
foreach ($fields as $field) {
|
||||
if ($request->has($field)) {
|
||||
$value = $request->input($field);
|
||||
Setting::set($field, is_string($value) ? trim($value) : $value);
|
||||
}
|
||||
}
|
||||
|
||||
Setting::flushCache();
|
||||
|
||||
return redirect()->route('admin.content.index')
|
||||
->with('success', 'Layout en teksten zijn direct opgeslagen en live bijgewerkt in de webshop!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset specific settings or all back to default.
|
||||
*/
|
||||
public function reset(): RedirectResponse
|
||||
{
|
||||
$keys = [
|
||||
'site_name', 'site_tagline', 'meta_description', 'theme_palette',
|
||||
'announcement_enabled', 'announcement_text', 'announcement_badge_1', 'announcement_badge_2',
|
||||
'hero_badge', 'hero_title', 'hero_subtitle', 'hero_primary_btn_text', 'hero_primary_btn_url',
|
||||
'hero_secondary_btn_text', 'hero_secondary_btn_url',
|
||||
'hero_stat_1_val', 'hero_stat_1_lbl', 'hero_stat_2_val', 'hero_stat_2_lbl', 'hero_stat_3_val', 'hero_stat_3_lbl',
|
||||
'hero_card_badge',
|
||||
'categories_tag', 'categories_title', 'categories_subtitle',
|
||||
'featured_tag', 'featured_title', 'featured_subtitle',
|
||||
'usp_tag', 'usp_title', 'usp_subtitle',
|
||||
'usp_1_title', 'usp_1_desc', 'usp_2_title', 'usp_2_desc', 'usp_3_title', 'usp_3_desc', 'usp_4_title', 'usp_4_desc',
|
||||
'usp_btn_text',
|
||||
'footer_description', 'footer_status_text', 'footer_email', 'footer_shipping_text', 'footer_copyright', 'footer_payment_text',
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
Setting::forget($key);
|
||||
}
|
||||
|
||||
Setting::flushCache();
|
||||
|
||||
return redirect()->route('admin.content.index')
|
||||
->with('success', 'Alle teksten en lay-out instellingen zijn hersteld naar de standaarden.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user