new design with nice layout
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use App\Models\ContactEnquiry;
|
||||
use App\Models\SiteSection;
|
||||
use App\Models\SiteSetting;
|
||||
use Livewire\Component;
|
||||
class Dashboard extends Component {
|
||||
public function render() {
|
||||
|
||||
class Dashboard extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.admin.dashboard', [
|
||||
'totalEnquiries'=>ContactEnquiry::count(), 'unreadEnquiries'=>ContactEnquiry::where('is_read',false)->count(),
|
||||
'sectionCount'=>SiteSection::count(), 'publishedSections'=>SiteSection::where('is_visible',true)->count(),
|
||||
'recentEnquiries'=>ContactEnquiry::latest()->limit(5)->get(),
|
||||
])->layout('layouts.admin', ['title'=>'Overview']);
|
||||
'totalEnquiries' => ContactEnquiry::count(), 'unreadEnquiries' => ContactEnquiry::where('is_read', false)->count(),
|
||||
'sectionCount' => SiteSection::count(), 'publishedSections' => SiteSection::where('is_visible', true)->count(),
|
||||
'recentEnquiries' => ContactEnquiry::latest()->limit(5)->get(),
|
||||
])->layout('layouts.admin', ['title' => 'Overview']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use App\Models\ContactEnquiry;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
class Enquiries extends Component {
|
||||
|
||||
class Enquiries extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
public string $filter='all';
|
||||
public function updatingFilter(): void { $this->resetPage(); }
|
||||
public function markRead(int $id): void { ContactEnquiry::findOrFail($id)->update(['is_read'=>true]); }
|
||||
public function delete(int $id): void { ContactEnquiry::findOrFail($id)->delete(); }
|
||||
public function render() {
|
||||
$query=ContactEnquiry::latest();
|
||||
if ($this->filter==='unread') $query->where('is_read',false);
|
||||
return view('livewire.admin.enquiries',['enquiries'=>$query->paginate(12)])->layout('layouts.admin',['title'=>'Enquiries']);
|
||||
|
||||
public string $filter = 'all';
|
||||
|
||||
public function updatingFilter(): void
|
||||
{
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
public function markRead(int $id): void
|
||||
{
|
||||
ContactEnquiry::findOrFail($id)->update(['is_read' => true]);
|
||||
}
|
||||
|
||||
public function delete(int $id): void
|
||||
{
|
||||
ContactEnquiry::findOrFail($id)->delete();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$query = ContactEnquiry::latest();
|
||||
if ($this->filter === 'unread') {
|
||||
$query->where('is_read', false);
|
||||
}
|
||||
|
||||
return view('livewire.admin.enquiries', ['enquiries' => $query->paginate(12)])->layout('layouts.admin', ['title' => 'Enquiries']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use App\Models\SiteSection;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Component;
|
||||
class Sections extends Component {
|
||||
|
||||
class Sections extends Component
|
||||
{
|
||||
public ?int $editingId = null;
|
||||
|
||||
public string $key = '';
|
||||
|
||||
public string $eyebrow = '';
|
||||
|
||||
public string $title = '';
|
||||
|
||||
public string $body = '';
|
||||
|
||||
public string $button_label = '';
|
||||
|
||||
public string $button_url = '';
|
||||
|
||||
public bool $is_visible = true;
|
||||
|
||||
public int $sort_order = 0;
|
||||
public function edit(int $id): void {
|
||||
$s=SiteSection::findOrFail($id);
|
||||
$this->editingId=$s->id;
|
||||
foreach (['key','eyebrow','title','body','button_label','button_url','is_visible','sort_order'] as $field) $this->$field=$s->$field ?? (is_bool($this->$field) ? false : '');
|
||||
|
||||
public function edit(int $id): void
|
||||
{
|
||||
$s = SiteSection::findOrFail($id);
|
||||
$this->editingId = $s->id;
|
||||
foreach (['key', 'eyebrow', 'title', 'body', 'button_label', 'button_url', 'is_visible', 'sort_order'] as $field) {
|
||||
$this->$field = $s->$field ?? (is_bool($this->$field) ? false : '');
|
||||
}
|
||||
}
|
||||
public function add(): void { $this->reset(['editingId','key','eyebrow','title','body','button_label','button_url','sort_order']); $this->is_visible=true; }
|
||||
public function save(): void {
|
||||
$data=$this->validate([
|
||||
'key'=>['required','alpha_dash','max:80', Rule::unique('site_sections','key')->ignore($this->editingId)],
|
||||
'eyebrow'=>'nullable|string|max:255','title'=>'required|string|max:255','body'=>'nullable|string|max:5000',
|
||||
'button_label'=>'nullable|string|max:100','button_url'=>'nullable|string|max:500',
|
||||
'is_visible'=>'boolean','sort_order'=>'integer|min:0|max:999',
|
||||
|
||||
public function add(): void
|
||||
{
|
||||
$this->reset(['editingId', 'key', 'eyebrow', 'title', 'body', 'button_label', 'button_url', 'sort_order']);
|
||||
$this->is_visible = true;
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$data = $this->validate([
|
||||
'key' => ['required', 'alpha_dash', 'max:80', Rule::unique('site_sections', 'key')->ignore($this->editingId)],
|
||||
'eyebrow' => 'nullable|string|max:255', 'title' => 'required|string|max:255', 'body' => 'nullable|string|max:5000',
|
||||
'button_label' => 'nullable|string|max:100', 'button_url' => 'nullable|string|max:500',
|
||||
'is_visible' => 'boolean', 'sort_order' => 'integer|min:0|max:999',
|
||||
]);
|
||||
SiteSection::updateOrCreate(['id'=>$this->editingId], $data);
|
||||
$this->add(); session()->flash('status','Section saved successfully.');
|
||||
SiteSection::updateOrCreate(['id' => $this->editingId], $data);
|
||||
$this->add();
|
||||
session()->flash('status', 'Section saved successfully.');
|
||||
}
|
||||
|
||||
public function toggle(int $id): void
|
||||
{
|
||||
$s = SiteSection::findOrFail($id);
|
||||
$s->update(['is_visible' => ! $s->is_visible]);
|
||||
}
|
||||
|
||||
public function delete(int $id): void
|
||||
{
|
||||
SiteSection::findOrFail($id)->delete();
|
||||
if ($this->editingId === $id) {
|
||||
$this->add();
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.admin.sections', ['sections' => SiteSection::orderBy('sort_order')->get()])->layout('layouts.admin', ['title' => 'Page sections']);
|
||||
}
|
||||
public function toggle(int $id): void { $s=SiteSection::findOrFail($id); $s->update(['is_visible'=>!$s->is_visible]); }
|
||||
public function delete(int $id): void { SiteSection::findOrFail($id)->delete(); if ($this->editingId===$id) $this->add(); }
|
||||
public function render() { return view('livewire.admin.sections',['sections'=>SiteSection::orderBy('sort_order')->get()])->layout('layouts.admin',['title'=>'Page sections']); }
|
||||
}
|
||||
|
||||
@@ -1,15 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use App\Models\SiteSetting;
|
||||
use Livewire\Component;
|
||||
class Settings extends Component {
|
||||
public string $site_name=''; public string $email=''; public string $footer_tagline=''; public string $location='';
|
||||
public function mount(): void { foreach (['site_name','email','footer_tagline','location'] as $key) $this->$key=SiteSetting::where('key',$key)->value('value') ?? ''; }
|
||||
public function save(): void {
|
||||
$data=$this->validate(['site_name'=>'required|string|max:100','email'=>'required|email|max:255',
|
||||
'footer_tagline'=>'nullable|string|max:255','location'=>'nullable|string|max:255']);
|
||||
foreach ($data as $key=>$value) SiteSetting::updateOrCreate(['key'=>$key],['value'=>$value]);
|
||||
session()->flash('status','Settings updated.');
|
||||
|
||||
class Settings extends Component
|
||||
{
|
||||
public string $site_name = '';
|
||||
|
||||
public string $email = '';
|
||||
|
||||
public string $footer_tagline = '';
|
||||
|
||||
public string $location = '';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
foreach (['site_name', 'email', 'footer_tagline', 'location'] as $key) {
|
||||
$this->$key = SiteSetting::where('key', $key)->value('value') ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$data = $this->validate(['site_name' => 'required|string|max:100', 'email' => 'required|email|max:255',
|
||||
'footer_tagline' => 'nullable|string|max:255', 'location' => 'nullable|string|max:255']);
|
||||
foreach ($data as $key => $value) {
|
||||
SiteSetting::updateOrCreate(['key' => $key], ['value' => $value]);
|
||||
}
|
||||
session()->flash('status', 'Settings updated.');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.admin.settings')->layout('layouts.admin', ['title' => 'Site settings']);
|
||||
}
|
||||
public function render() { return view('livewire.admin.settings')->layout('layouts.admin',['title'=>'Site settings']); }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\ContactEnquiry;
|
||||
use Illuminate\Mail\Message;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -8,21 +10,30 @@ use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
use function Illuminate\Support\defer;
|
||||
class ContactForm extends Component {
|
||||
|
||||
class ContactForm extends Component
|
||||
{
|
||||
public string $name = '';
|
||||
|
||||
public string $email = '';
|
||||
|
||||
public string $company = '';
|
||||
|
||||
public string $service = '';
|
||||
|
||||
public string $message = '';
|
||||
|
||||
public string $website = '';
|
||||
|
||||
public bool $submitted = false;
|
||||
|
||||
/** Save a valid enquiry before attempting its email notification. */
|
||||
public function submit(): void
|
||||
{
|
||||
$this->validate(['name'=>'required|string|max:120','email'=>'required|email|max:255','company'=>'nullable|string|max:120',
|
||||
'service'=>'nullable|string|max:100','message'=>'required|string|min:10|max:5000','website'=>'nullable|max:0']);
|
||||
$enquiry = ContactEnquiry::create($this->only(['name','email','company','service','message']));
|
||||
$this->reset(['name','email','company','service','message']);
|
||||
$this->validate(['name' => 'required|string|max:120', 'email' => 'required|email|max:255', 'company' => 'nullable|string|max:120',
|
||||
'service' => 'nullable|string|max:100', 'message' => 'required|string|min:10|max:5000', 'website' => 'nullable|max:0']);
|
||||
$enquiry = ContactEnquiry::create($this->only(['name', 'email', 'company', 'service', 'message']));
|
||||
$this->reset(['name', 'email', 'company', 'service', 'message']);
|
||||
$this->submitted = true;
|
||||
|
||||
defer(fn () => $this->notifyByEmail($enquiry))->always();
|
||||
@@ -69,5 +80,8 @@ class ContactForm extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
public function render() { return view('livewire.contact-form'); }
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.contact-form');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user