new design with nice layout
This commit is contained in:
@@ -1,18 +1,39 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
class CreateAdmin extends Command {
|
|
||||||
protected $signature='absdev:create-admin {email}';
|
class CreateAdmin extends Command
|
||||||
protected $description='Create or promote an administrator (password entered securely)';
|
{
|
||||||
public function handle(): int {
|
protected $signature = 'absdev:create-admin {email}';
|
||||||
$email=$this->argument('email');
|
|
||||||
if (!filter_var($email,FILTER_VALIDATE_EMAIL)) { $this->error('Invalid email address.'); return self::FAILURE; }
|
protected $description = 'Create or promote an administrator (password entered securely)';
|
||||||
$password=$this->secret('Password (minimum 12 characters)');
|
|
||||||
if (!is_string($password) || strlen($password)<12) { $this->error('Password must be at least 12 characters.'); return self::FAILURE; }
|
public function handle(): int
|
||||||
$user=User::firstOrNew(['email'=>$email]);
|
{
|
||||||
if (!$user->exists) $user->name=$this->ask('Administrator name','Administrator');
|
$email = $this->argument('email');
|
||||||
$user->password=$password; $user->is_admin=true; $user->save();
|
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
$this->info('Administrator account ready.'); return self::SUCCESS;
|
$this->error('Invalid email address.');
|
||||||
|
|
||||||
|
return self::FAILURE;
|
||||||
|
}
|
||||||
|
$password = $this->secret('Password (minimum 12 characters)');
|
||||||
|
if (! is_string($password) || strlen($password) < 12) {
|
||||||
|
$this->error('Password must be at least 12 characters.');
|
||||||
|
|
||||||
|
return self::FAILURE;
|
||||||
|
}
|
||||||
|
$user = User::firstOrNew(['email' => $email]);
|
||||||
|
if (! $user->exists) {
|
||||||
|
$user->name = $this->ask('Administrator name', 'Administrator');
|
||||||
|
}
|
||||||
|
$user->password = $password;
|
||||||
|
$user->is_admin = true;
|
||||||
|
$user->save();
|
||||||
|
$this->info('Administrator account ready.');
|
||||||
|
|
||||||
|
return self::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,36 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Auth;
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
class LoginController extends Controller {
|
|
||||||
public function show() { return view('auth.login'); }
|
class LoginController extends Controller
|
||||||
public function login(Request $request) {
|
{
|
||||||
$credentials=$request->validate(['email'=>'required|email','password'=>'required|string']);
|
public function show()
|
||||||
if (!Auth::attempt([...$credentials,'is_admin'=>true],$request->boolean('remember'))) {
|
{
|
||||||
throw ValidationException::withMessages(['email'=>'Invalid administrator credentials.']);
|
return view('auth.login');
|
||||||
}
|
|
||||||
$request->session()->regenerate(); return redirect()->intended(route('admin.dashboard'));
|
|
||||||
}
|
}
|
||||||
public function logout(Request $request) {
|
|
||||||
Auth::logout(); $request->session()->invalidate(); $request->session()->regenerateToken();
|
public function login(Request $request)
|
||||||
|
{
|
||||||
|
$credentials = $request->validate(['email' => 'required|email', 'password' => 'required|string']);
|
||||||
|
if (! Auth::attempt([...$credentials, 'is_admin' => true], $request->boolean('remember'))) {
|
||||||
|
throw ValidationException::withMessages(['email' => 'Invalid administrator credentials.']);
|
||||||
|
}
|
||||||
|
$request->session()->regenerate();
|
||||||
|
|
||||||
|
return redirect()->intended(route('admin.dashboard'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logout(Request $request)
|
||||||
|
{
|
||||||
|
Auth::logout();
|
||||||
|
$request->session()->invalidate();
|
||||||
|
$request->session()->regenerateToken();
|
||||||
|
|
||||||
return redirect()->route('login');
|
return redirect()->route('login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
class EnsureAdmin {
|
|
||||||
public function handle(Request $request, Closure $next): Response {
|
class EnsureAdmin
|
||||||
abort_unless($request->user()?->is_admin,403);
|
{
|
||||||
|
public function handle(Request $request, Closure $next): Response
|
||||||
|
{
|
||||||
|
abort_unless($request->user()?->is_admin, 403);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Livewire\Admin;
|
namespace App\Livewire\Admin;
|
||||||
|
|
||||||
use App\Models\ContactEnquiry;
|
use App\Models\ContactEnquiry;
|
||||||
use App\Models\SiteSection;
|
use App\Models\SiteSection;
|
||||||
use App\Models\SiteSetting;
|
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
class Dashboard extends Component {
|
|
||||||
public function render() {
|
class Dashboard extends Component
|
||||||
|
{
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
return view('livewire.admin.dashboard', [
|
return view('livewire.admin.dashboard', [
|
||||||
'totalEnquiries'=>ContactEnquiry::count(), 'unreadEnquiries'=>ContactEnquiry::where('is_read',false)->count(),
|
'totalEnquiries' => ContactEnquiry::count(), 'unreadEnquiries' => ContactEnquiry::where('is_read', false)->count(),
|
||||||
'sectionCount'=>SiteSection::count(), 'publishedSections'=>SiteSection::where('is_visible',true)->count(),
|
'sectionCount' => SiteSection::count(), 'publishedSections' => SiteSection::where('is_visible', true)->count(),
|
||||||
'recentEnquiries'=>ContactEnquiry::latest()->limit(5)->get(),
|
'recentEnquiries' => ContactEnquiry::latest()->limit(5)->get(),
|
||||||
])->layout('layouts.admin', ['title'=>'Overview']);
|
])->layout('layouts.admin', ['title' => 'Overview']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,39 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Livewire\Admin;
|
namespace App\Livewire\Admin;
|
||||||
|
|
||||||
use App\Models\ContactEnquiry;
|
use App\Models\ContactEnquiry;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Livewire\WithPagination;
|
use Livewire\WithPagination;
|
||||||
class Enquiries extends Component {
|
|
||||||
|
class Enquiries extends Component
|
||||||
|
{
|
||||||
use WithPagination;
|
use WithPagination;
|
||||||
public string $filter='all';
|
|
||||||
public function updatingFilter(): void { $this->resetPage(); }
|
public string $filter = 'all';
|
||||||
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 updatingFilter(): void
|
||||||
public function render() {
|
{
|
||||||
$query=ContactEnquiry::latest();
|
$this->resetPage();
|
||||||
if ($this->filter==='unread') $query->where('is_read',false);
|
}
|
||||||
return view('livewire.admin.enquiries',['enquiries'=>$query->paginate(12)])->layout('layouts.admin',['title'=>'Enquiries']);
|
|
||||||
|
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
|
<?php
|
||||||
|
|
||||||
namespace App\Livewire\Admin;
|
namespace App\Livewire\Admin;
|
||||||
|
|
||||||
use App\Models\SiteSection;
|
use App\Models\SiteSection;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
class Sections extends Component {
|
|
||||||
|
class Sections extends Component
|
||||||
|
{
|
||||||
public ?int $editingId = null;
|
public ?int $editingId = null;
|
||||||
|
|
||||||
public string $key = '';
|
public string $key = '';
|
||||||
|
|
||||||
public string $eyebrow = '';
|
public string $eyebrow = '';
|
||||||
|
|
||||||
public string $title = '';
|
public string $title = '';
|
||||||
|
|
||||||
public string $body = '';
|
public string $body = '';
|
||||||
|
|
||||||
public string $button_label = '';
|
public string $button_label = '';
|
||||||
|
|
||||||
public string $button_url = '';
|
public string $button_url = '';
|
||||||
|
|
||||||
public bool $is_visible = true;
|
public bool $is_visible = true;
|
||||||
|
|
||||||
public int $sort_order = 0;
|
public int $sort_order = 0;
|
||||||
public function edit(int $id): void {
|
|
||||||
$s=SiteSection::findOrFail($id);
|
public function edit(int $id): void
|
||||||
$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 : '');
|
$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 {
|
public function add(): void
|
||||||
$data=$this->validate([
|
{
|
||||||
'key'=>['required','alpha_dash','max:80', Rule::unique('site_sections','key')->ignore($this->editingId)],
|
$this->reset(['editingId', 'key', 'eyebrow', 'title', 'body', 'button_label', 'button_url', 'sort_order']);
|
||||||
'eyebrow'=>'nullable|string|max:255','title'=>'required|string|max:255','body'=>'nullable|string|max:5000',
|
$this->is_visible = true;
|
||||||
'button_label'=>'nullable|string|max:100','button_url'=>'nullable|string|max:500',
|
}
|
||||||
'is_visible'=>'boolean','sort_order'=>'integer|min:0|max:999',
|
|
||||||
|
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);
|
SiteSection::updateOrCreate(['id' => $this->editingId], $data);
|
||||||
$this->add(); session()->flash('status','Section saved successfully.');
|
$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
|
<?php
|
||||||
|
|
||||||
namespace App\Livewire\Admin;
|
namespace App\Livewire\Admin;
|
||||||
|
|
||||||
use App\Models\SiteSetting;
|
use App\Models\SiteSetting;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
class Settings extends Component {
|
|
||||||
public string $site_name=''; public string $email=''; public string $footer_tagline=''; public string $location='';
|
class Settings extends Component
|
||||||
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 {
|
public string $site_name = '';
|
||||||
$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']);
|
public string $email = '';
|
||||||
foreach ($data as $key=>$value) SiteSetting::updateOrCreate(['key'=>$key],['value'=>$value]);
|
|
||||||
session()->flash('status','Settings updated.');
|
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
|
<?php
|
||||||
|
|
||||||
namespace App\Livewire;
|
namespace App\Livewire;
|
||||||
|
|
||||||
use App\Models\ContactEnquiry;
|
use App\Models\ContactEnquiry;
|
||||||
use Illuminate\Mail\Message;
|
use Illuminate\Mail\Message;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@@ -8,21 +10,30 @@ use Livewire\Component;
|
|||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
use function Illuminate\Support\defer;
|
use function Illuminate\Support\defer;
|
||||||
class ContactForm extends Component {
|
|
||||||
|
class ContactForm extends Component
|
||||||
|
{
|
||||||
public string $name = '';
|
public string $name = '';
|
||||||
|
|
||||||
public string $email = '';
|
public string $email = '';
|
||||||
|
|
||||||
public string $company = '';
|
public string $company = '';
|
||||||
|
|
||||||
public string $service = '';
|
public string $service = '';
|
||||||
|
|
||||||
public string $message = '';
|
public string $message = '';
|
||||||
|
|
||||||
public string $website = '';
|
public string $website = '';
|
||||||
|
|
||||||
public bool $submitted = false;
|
public bool $submitted = false;
|
||||||
|
|
||||||
/** Save a valid enquiry before attempting its email notification. */
|
/** Save a valid enquiry before attempting its email notification. */
|
||||||
public function submit(): void
|
public function submit(): void
|
||||||
{
|
{
|
||||||
$this->validate(['name'=>'required|string|max:120','email'=>'required|email|max:255','company'=>'nullable|string|max:120',
|
$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']);
|
'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']));
|
$enquiry = ContactEnquiry::create($this->only(['name', 'email', 'company', 'service', 'message']));
|
||||||
$this->reset(['name','email','company','service','message']);
|
$this->reset(['name', 'email', 'company', 'service', 'message']);
|
||||||
$this->submitted = true;
|
$this->submitted = true;
|
||||||
|
|
||||||
defer(fn () => $this->notifyByEmail($enquiry))->always();
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
class ContactEnquiry extends Model {
|
|
||||||
protected $fillable = ['name','email','company','service','message','is_read'];
|
class ContactEnquiry extends Model
|
||||||
protected function casts(): array { return ['is_read'=>'boolean']; }
|
{
|
||||||
|
protected $fillable = ['name', 'email', 'company', 'service', 'message', 'is_read'];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return ['is_read' => 'boolean'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
class SiteSection extends Model {
|
|
||||||
protected $fillable = ['key','eyebrow','title','body','button_label','button_url','is_visible','sort_order'];
|
class SiteSection extends Model
|
||||||
protected function casts(): array { return ['is_visible'=>'boolean','sort_order'=>'integer']; }
|
{
|
||||||
|
protected $fillable = ['key', 'eyebrow', 'title', 'body', 'button_label', 'button_url', 'is_visible', 'sort_order'];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return ['is_visible' => 'boolean', 'sort_order' => 'integer'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
class SiteSetting extends Model { protected $fillable = ['key','value']; }
|
|
||||||
|
class SiteSetting extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = ['key', 'value'];
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"predis/predis": "^3.7"
|
"predis/predis": "^3.7"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"deployer/deployer": "^8.0",
|
||||||
"fakerphp/faker": "^1.23",
|
"fakerphp/faker": "^1.23",
|
||||||
"laravel/pail": "^1.2.5",
|
"laravel/pail": "^1.2.5",
|
||||||
"laravel/pao": "^1.0.6",
|
"laravel/pao": "^1.0.6",
|
||||||
|
|||||||
@@ -4,26 +4,46 @@ use Illuminate\Database\Migrations\Migration;
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration {
|
return new class extends Migration
|
||||||
public function up(): void {
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
Schema::table('users', fn (Blueprint $table) => $table->boolean('is_admin')->default(false));
|
Schema::table('users', fn (Blueprint $table) => $table->boolean('is_admin')->default(false));
|
||||||
Schema::create('site_sections', function (Blueprint $table) {
|
Schema::create('site_sections', function (Blueprint $table) {
|
||||||
$table->id(); $table->string('key')->unique(); $table->string('eyebrow')->nullable();
|
$table->id();
|
||||||
$table->string('title'); $table->text('body')->nullable(); $table->string('button_label')->nullable();
|
$table->string('key')->unique();
|
||||||
$table->string('button_url')->nullable(); $table->boolean('is_visible')->default(true);
|
$table->string('eyebrow')->nullable();
|
||||||
$table->unsignedInteger('sort_order')->default(0); $table->timestamps();
|
$table->string('title');
|
||||||
|
$table->text('body')->nullable();
|
||||||
|
$table->string('button_label')->nullable();
|
||||||
|
$table->string('button_url')->nullable();
|
||||||
|
$table->boolean('is_visible')->default(true);
|
||||||
|
$table->unsignedInteger('sort_order')->default(0);
|
||||||
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
Schema::create('site_settings', function (Blueprint $table) {
|
Schema::create('site_settings', function (Blueprint $table) {
|
||||||
$table->id(); $table->string('key')->unique(); $table->text('value')->nullable(); $table->timestamps();
|
$table->id();
|
||||||
|
$table->string('key')->unique();
|
||||||
|
$table->text('value')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
Schema::create('contact_enquiries', function (Blueprint $table) {
|
Schema::create('contact_enquiries', function (Blueprint $table) {
|
||||||
$table->id(); $table->string('name'); $table->string('email'); $table->string('company')->nullable();
|
$table->id();
|
||||||
$table->string('service')->nullable(); $table->text('message'); $table->boolean('is_read')->default(false);
|
$table->string('name');
|
||||||
|
$table->string('email');
|
||||||
|
$table->string('company')->nullable();
|
||||||
|
$table->string('service')->nullable();
|
||||||
|
$table->text('message');
|
||||||
|
$table->boolean('is_read')->default(false);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public function down(): void {
|
|
||||||
Schema::dropIfExists('contact_enquiries'); Schema::dropIfExists('site_settings');
|
public function down(): void
|
||||||
Schema::dropIfExists('site_sections'); Schema::table('users', fn (Blueprint $table) => $table->dropColumn('is_admin'));
|
{
|
||||||
|
Schema::dropIfExists('contact_enquiries');
|
||||||
|
Schema::dropIfExists('site_settings');
|
||||||
|
Schema::dropIfExists('site_sections');
|
||||||
|
Schema::table('users', fn (Blueprint $table) => $table->dropColumn('is_admin'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
class DatabaseSeeder extends Seeder { public function run(): void { $this->call(SiteContentSeeder::class); } }
|
|
||||||
|
class DatabaseSeeder extends Seeder
|
||||||
|
{
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
$this->call(SiteContentSeeder::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,22 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use App\Models\SiteSection;
|
use App\Models\SiteSection;
|
||||||
use App\Models\SiteSetting;
|
use App\Models\SiteSetting;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
class SiteContentSeeder extends Seeder {
|
|
||||||
public function run(): void {
|
class SiteContentSeeder extends Seeder
|
||||||
|
{
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
$sections = [
|
$sections = [
|
||||||
['hero','Independent by design. Exceptional by default.','Digital experiences built to move your business forward.','We craft considered software, polished websites, and practical digital products for ambitious businesses. From the first sketch to the final deployment, every detail matters.','Start a project','#contact'],
|
['hero', 'Independent by design. Exceptional by default.', 'Digital experiences built to move your business forward.', 'We craft considered software, polished websites, and practical digital products for ambitious businesses. From the first sketch to the final deployment, every detail matters.', 'Start a project', '#contact'],
|
||||||
['services','WHAT WE DO','Technology with a human touch.','Strategy, design and engineering working together. Modern tools, clear thinking and software that genuinely earns its place.','Explore our services','#services'],
|
['services', 'WHAT WE DO', 'Technology with a human touch.', 'Strategy, design and engineering working together. Modern tools, clear thinking and software that genuinely earns its place.', 'Explore our services', '#services'],
|
||||||
['approach','HOW WE WORK','Small team energy. Big picture thinking.','Direct collaboration, honest communication and a relentless focus on outcomes. We keep projects agile, transparent and built for the long term.','Our process','#process'],
|
['approach', 'HOW WE WORK', 'Small team energy. Big picture thinking.', 'Direct collaboration, honest communication and a relentless focus on outcomes. We keep projects agile, transparent and built for the long term.', 'Our process', '#process'],
|
||||||
['work','SELECTED EXPERTISE','From complex challenges to elegant solutions.','We turn real-world problems into streamlined systems, thoughtful products and reliable digital infrastructure.','Talk about your idea','#contact'],
|
['work', 'SELECTED EXPERTISE', 'From complex challenges to elegant solutions.', 'We turn real-world problems into streamlined systems, thoughtful products and reliable digital infrastructure.', 'Talk about your idea', '#contact'],
|
||||||
['cta','LET’S BUILD SOMETHING','Your next chapter starts with a conversation.','Tell us what you are building. We will help map out the smartest way forward.','Get in touch','#contact'],
|
['cta', 'LET’S BUILD SOMETHING', 'Your next chapter starts with a conversation.', 'Tell us what you are building. We will help map out the smartest way forward.', 'Get in touch', '#contact'],
|
||||||
];
|
];
|
||||||
foreach ($sections as $i => [$key,$eyebrow,$title,$body,$button,$url]) {
|
foreach ($sections as $i => [$key,$eyebrow,$title,$body,$button,$url]) {
|
||||||
SiteSection::firstOrCreate(['key'=>$key], ['eyebrow'=>$eyebrow,'title'=>$title,'body'=>$body,'button_label'=>$button,'button_url'=>$url,'sort_order'=>$i]);
|
SiteSection::firstOrCreate(['key' => $key], ['eyebrow' => $eyebrow, 'title' => $title, 'body' => $body, 'button_label' => $button, 'button_url' => $url, 'sort_order' => $i]);
|
||||||
}
|
}
|
||||||
foreach (['site_name'=>'ABSDEV','email'=>'[email protected]','footer_tagline'=>'Independent software. Thoughtfully engineered.','location'=>'United Kingdom'] as $key=>$value) {
|
foreach (['site_name' => 'ABSDEV', 'email' => '[email protected]', 'footer_tagline' => 'Independent software. Thoughtfully engineered.', 'location' => 'United Kingdom'] as $key => $value) {
|
||||||
SiteSetting::firstOrCreate(['key'=>$key], ['value'=>$value]);
|
SiteSetting::firstOrCreate(['key' => $key], ['value' => $value]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-10
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\Auth\LoginController;
|
use App\Http\Controllers\Auth\LoginController;
|
||||||
use App\Http\Middleware\EnsureAdmin;
|
use App\Http\Middleware\EnsureAdmin;
|
||||||
use App\Livewire\Admin\Dashboard;
|
use App\Livewire\Admin\Dashboard;
|
||||||
@@ -11,8 +12,8 @@ use Illuminate\Support\Facades\Route;
|
|||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return view('welcome', [
|
return view('welcome', [
|
||||||
'sections'=>SiteSection::where('is_visible',true)->orderBy('sort_order')->get()->keyBy('key'),
|
'sections' => SiteSection::where('is_visible', true)->orderBy('sort_order')->get()->keyBy('key'),
|
||||||
'settings'=>SiteSetting::pluck('value','key'),
|
'settings' => SiteSetting::pluck('value', 'key'),
|
||||||
]);
|
]);
|
||||||
})->name('home');
|
})->name('home');
|
||||||
// Dedicated public service, expertise and process pages.
|
// Dedicated public service, expertise and process pages.
|
||||||
@@ -27,13 +28,13 @@ foreach (['services', 'expertise', 'approach'] as $slug) {
|
|||||||
})->name($slug);
|
})->name($slug);
|
||||||
}
|
}
|
||||||
Route::middleware('guest')->group(function () {
|
Route::middleware('guest')->group(function () {
|
||||||
Route::get('/admin/login',[LoginController::class,'show'])->name('login');
|
Route::get('/admin/login', [LoginController::class, 'show'])->name('login');
|
||||||
Route::post('/admin/login',[LoginController::class,'login'])->middleware('throttle:5,1')->name('login.submit');
|
Route::post('/admin/login', [LoginController::class, 'login'])->middleware('throttle:5,1')->name('login.submit');
|
||||||
});
|
});
|
||||||
Route::post('/admin/logout',[LoginController::class,'logout'])->middleware('auth')->name('logout');
|
Route::post('/admin/logout', [LoginController::class, 'logout'])->middleware('auth')->name('logout');
|
||||||
Route::prefix('admin')->name('admin.')->middleware(['auth',EnsureAdmin::class])->group(function () {
|
Route::prefix('admin')->name('admin.')->middleware(['auth', EnsureAdmin::class])->group(function () {
|
||||||
Route::get('/',Dashboard::class)->name('dashboard');
|
Route::get('/', Dashboard::class)->name('dashboard');
|
||||||
Route::get('/sections',Sections::class)->name('sections');
|
Route::get('/sections', Sections::class)->name('sections');
|
||||||
Route::get('/enquiries',Enquiries::class)->name('enquiries');
|
Route::get('/enquiries', Enquiries::class)->name('enquiries');
|
||||||
Route::get('/settings',Settings::class)->name('settings');
|
Route::get('/settings', Settings::class)->name('settings');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,19 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\SiteSection;
|
||||||
|
use Database\Seeders\SiteContentSeeder;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
class AbsdevBrandAndHomeTest extends TestCase {
|
|
||||||
|
class AbsdevBrandAndHomeTest extends TestCase
|
||||||
|
{
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
public function test_homepage_has_a_complete_hero_without_seed_data(): void {
|
|
||||||
|
public function test_homepage_has_a_complete_hero_without_seed_data(): void
|
||||||
|
{
|
||||||
$this->get('/')->assertOk()->assertSee('Ideas')->assertSee('Technology with a human touch.');
|
$this->get('/')->assertOk()->assertSee('Ideas')->assertSee('Technology with a human touch.');
|
||||||
}
|
}
|
||||||
public function test_homepage_links_to_the_new_pages_and_favicon(): void {
|
|
||||||
|
public function test_homepage_links_to_the_new_pages_and_favicon(): void
|
||||||
|
{
|
||||||
$this->get('/')->assertOk()->assertSee('/favicon.svg')->assertSee('href="'.route('services').'"', false)
|
$this->get('/')->assertOk()->assertSee('/favicon.svg')->assertSee('href="'.route('services').'"', false)
|
||||||
->assertSee('href="'.route('expertise').'"', false)->assertSee('href="'.route('approach').'"', false);
|
->assertSee('href="'.route('expertise').'"', false)->assertSee('href="'.route('approach').'"', false);
|
||||||
}
|
}
|
||||||
public function test_hidden_cms_section_stays_hidden(): void {
|
|
||||||
$this->seed(\Database\Seeders\SiteContentSeeder::class);
|
public function test_hidden_cms_section_stays_hidden(): void
|
||||||
\App\Models\SiteSection::where('key','hero')->update(['is_visible'=>false]);
|
{
|
||||||
$this->get('/')->assertOk()->assertDontSee('Ideas<span',false);
|
$this->seed(SiteContentSeeder::class);
|
||||||
|
SiteSection::where('key', 'hero')->update(['is_visible' => false]);
|
||||||
|
$this->get('/')->assertOk()->assertDontSee('Ideas<span', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
use App\Livewire\ContactForm;
|
|
||||||
use App\Livewire\Admin\Sections;
|
use App\Livewire\Admin\Sections;
|
||||||
|
use App\Livewire\ContactForm;
|
||||||
use App\Models\ContactEnquiry;
|
use App\Models\ContactEnquiry;
|
||||||
use App\Models\SiteSection;
|
use App\Models\SiteSection;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -9,43 +11,64 @@ use Database\Seeders\SiteContentSeeder;
|
|||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
class SiteExperienceTest extends TestCase {
|
|
||||||
|
class SiteExperienceTest extends TestCase
|
||||||
|
{
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
public function test_homepage_displays_published_content(): void {
|
|
||||||
|
public function test_homepage_displays_published_content(): void
|
||||||
|
{
|
||||||
$this->seed(SiteContentSeeder::class);
|
$this->seed(SiteContentSeeder::class);
|
||||||
$this->get('/')->assertOk()->assertSee('Digital experiences built to move your business forward.');
|
$this->get('/')->assertOk()->assertSee('Digital experiences built to move your business forward.');
|
||||||
SiteSection::where('key','hero')->update(['is_visible'=>false]);
|
SiteSection::where('key', 'hero')->update(['is_visible' => false]);
|
||||||
$this->get('/')->assertOk()->assertDontSee('Digital experiences built to move your business forward.');
|
$this->get('/')->assertOk()->assertDontSee('Digital experiences built to move your business forward.');
|
||||||
}
|
}
|
||||||
public function test_contact_form_validates_and_saves_enquiry(): void {
|
|
||||||
Livewire::test(ContactForm::class)->set('name','Test Client')->set('email','[email protected]')
|
public function test_contact_form_validates_and_saves_enquiry(): void
|
||||||
->set('message','Please build a Laravel website for my business.')->call('submit')->assertHasNoErrors();
|
{
|
||||||
$this->assertDatabaseHas('contact_enquiries',['email'=>'[email protected]','is_read'=>false]);
|
Livewire::test(ContactForm::class)->set('name', 'Test Client')->set('email', '[email protected]')
|
||||||
|
->set('message', 'Please build a Laravel website for my business.')->call('submit')->assertHasNoErrors();
|
||||||
|
$this->assertDatabaseHas('contact_enquiries', ['email' => '[email protected]', 'is_read' => false]);
|
||||||
}
|
}
|
||||||
public function test_guests_cannot_open_admin_dashboard(): void { $this->get('/admin')->assertRedirect(route('login')); }
|
|
||||||
public function test_non_admin_cannot_access_admin_pages(): void {
|
public function test_guests_cannot_open_admin_dashboard(): void
|
||||||
|
{
|
||||||
|
$this->get('/admin')->assertRedirect(route('login'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_non_admin_cannot_access_admin_pages(): void
|
||||||
|
{
|
||||||
$this->actingAs(User::factory()->create())->get('/admin')->assertForbidden();
|
$this->actingAs(User::factory()->create())->get('/admin')->assertForbidden();
|
||||||
}
|
}
|
||||||
public function test_admin_can_edit_site_content(): void {
|
|
||||||
$admin=User::factory()->create(['is_admin'=>true]); $this->actingAs($admin);
|
public function test_admin_can_edit_site_content(): void
|
||||||
Livewire::test(Sections::class)->set('key','hero')->set('title','A better digital future')
|
{
|
||||||
->set('body','Custom messaging')->set('is_visible',true)->call('save')->assertHasNoErrors();
|
$admin = User::factory()->create(['is_admin' => true]);
|
||||||
$this->assertDatabaseHas('site_sections',['key'=>'hero','title'=>'A better digital future']);
|
$this->actingAs($admin);
|
||||||
|
Livewire::test(Sections::class)->set('key', 'hero')->set('title', 'A better digital future')
|
||||||
|
->set('body', 'Custom messaging')->set('is_visible', true)->call('save')->assertHasNoErrors();
|
||||||
|
$this->assertDatabaseHas('site_sections', ['key' => 'hero', 'title' => 'A better digital future']);
|
||||||
}
|
}
|
||||||
public function test_dedicated_public_pages_render_with_navigation_and_content(): void {
|
|
||||||
|
public function test_dedicated_public_pages_render_with_navigation_and_content(): void
|
||||||
|
{
|
||||||
foreach (['services' => 'Digital services', 'expertise' => 'Deep engineering', 'approach' => 'A clear process'] as $url => $heading) {
|
foreach (['services' => 'Digital services', 'expertise' => 'Deep engineering', 'approach' => 'A clear process'] as $url => $heading) {
|
||||||
$this->get('/'.$url)->assertOk()->assertSee($heading)->assertSee('Capability with purpose');
|
$this->get('/'.$url)->assertOk()->assertSee($heading)->assertSee('Capability with purpose');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public function test_homepage_navigation_links_to_dedicated_pages(): void {
|
|
||||||
|
public function test_homepage_navigation_links_to_dedicated_pages(): void
|
||||||
|
{
|
||||||
$this->seed(SiteContentSeeder::class);
|
$this->seed(SiteContentSeeder::class);
|
||||||
$this->get('/')->assertOk()->assertSee('href="'.route('services').'"', false)
|
$this->get('/')->assertOk()->assertSee('href="'.route('services').'"', false)
|
||||||
->assertSee('href="'.route('expertise').'"', false)
|
->assertSee('href="'.route('expertise').'"', false)
|
||||||
->assertSee('href="'.route('approach').'"', false);
|
->assertSee('href="'.route('approach').'"', false);
|
||||||
}
|
}
|
||||||
public function test_honeypot_rejects_spam(): void {
|
|
||||||
Livewire::test(ContactForm::class)->set('name','Spam')->set('email','[email protected]')
|
public function test_honeypot_rejects_spam(): void
|
||||||
->set('message','Spam message example')->set('website','spambot')->call('submit')->assertHasErrors(['website']);
|
{
|
||||||
$this->assertSame(0,ContactEnquiry::count());
|
Livewire::test(ContactForm::class)->set('name', 'Spam')->set('email', '[email protected]')
|
||||||
|
->set('message', 'Spam message example')->set('website', 'spambot')->call('submit')->assertHasErrors(['website']);
|
||||||
|
$this->assertSame(0, ContactEnquiry::count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user