phase two updates

This commit is contained in:
Mark Gregory
2026-07-24 09:45:41 +01:00
parent c2a19a16e6
commit 9204625c2f
114 changed files with 1480 additions and 1 deletions
+3
View File
@@ -0,0 +1,3 @@
<?php
return ['name' => 'Testimonials'];
@@ -0,0 +1,16 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void { Schema::create('testimonials', function (Blueprint $table): void { $table->id();
$table->string('name');
$table->string('company')->nullable();
$table->unsignedInteger('rating')->default(5);
$table->boolean('enabled')->default(true);
$table->timestamps(); $table->softDeletes(); }); }
public function down(): void { Schema::dropIfExists('testimonials'); }
};
@@ -0,0 +1,27 @@
<?php
namespace Modules\Testimonials\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Modules\Testimonials\Models\Testimonial;
final class TestimonialController extends Controller
{
public function index(): View { return view('testimonials::admin.index', ['records' => Testimonial::query()->latest()->paginate(20)]); }
public function create(): View { return view('testimonials::admin.form'); }
public function store(Request $request): RedirectResponse { $data = $request->validate(['name' => ['required', 'string', 'max:255'],
'company' => ['nullable', 'string'],
'content' => ['required', 'string'],
'rating' => ['nullable', 'integer', 'min:0'],
'enabled' => ['sometimes', 'boolean']]); $data['enabled'] = $request->boolean('enabled'); Testimonial::create($data); return redirect()->route('testimonials.index')->with('status', 'Testimonial created.'); }
public function edit(Testimonial $testimonial): View { return view('testimonials::admin.form', ['record' => $testimonial]); }
public function update(Request $request, Testimonial $testimonial): RedirectResponse { $data = $request->validate(['name' => ['required', 'string', 'max:255'],
'company' => ['nullable', 'string'],
'content' => ['required', 'string'],
'rating' => ['nullable', 'integer', 'min:0'],
'enabled' => ['sometimes', 'boolean']]); $data['enabled'] = $request->boolean('enabled'); $testimonial->update($data); return redirect()->route('testimonials.index')->with('status', 'Testimonial updated.'); }
public function destroy(Testimonial $testimonial): RedirectResponse { $testimonial->delete(); return back()->with('status', 'Testimonial deleted.'); }
}
@@ -0,0 +1,20 @@
<?php
namespace Modules\Testimonials\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
final class Testimonial extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'testimonials';
protected $fillable = ['name', 'company', 'content', 'rating', 'enabled'];
protected function casts(): array { return [
'rating' => 'integer',
'enabled' => 'boolean'
]; }
}
@@ -0,0 +1,15 @@
<?php
namespace Modules\Testimonials\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
final class RouteServiceProvider extends ServiceProvider
{
public function boot(): void
{
parent::boot();
$this->routes(fn () => Route::middleware('web')->group(module_path('Testimonials', 'Routes/web.php')));
}
}
@@ -0,0 +1,20 @@
<?php
namespace Modules\Testimonials\Providers;
use Illuminate\Support\ServiceProvider;
final class TestimonialsServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->register(RouteServiceProvider::class);
$this->mergeConfigFrom(module_path('Testimonials', 'Config/config.php'), 'testimonials');
}
public function boot(): void
{
$this->loadMigrationsFrom(module_path('Testimonials', 'Database/Migrations'));
$this->loadViewsFrom(module_path('Testimonials', 'Resources/views'), 'testimonials');
}
}
@@ -0,0 +1,9 @@
<x-layouts.app :title="isset($record) ? __('Edit Testimonial') : __('Create Testimonial')">
<div class="mx-auto max-w-4xl space-y-6"><div><h1 class="text-2xl font-semibold">{{ isset($record) ? 'Edit' : 'Create' }} Testimonial</h1></div><form method="POST" action="{{ isset($record) ? route('administration.testimonials.update', $record) : route('administration.testimonials.store') }}" class="space-y-5 rounded-xl border border-zinc-200 bg-white p-6 dark:border-zinc-700 dark:bg-zinc-900">@csrf @isset($record) @method('PUT') @endisset
<div><label class="mb-1 block text-sm font-medium">Name</label><input type="text" name="name" value="{{ old('name', $record->name ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('name')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<div><label class="mb-1 block text-sm font-medium">Company</label><input type="text" name="company" value="{{ old('company', $record->company ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('company')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<div><label class="mb-1 block text-sm font-medium">Content</label><textarea name="content" rows="4" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">{{ old('content', $record->content ?? '') }}</textarea>@error('content')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<div><label class="mb-1 block text-sm font-medium">Rating</label><input type="number" name="rating" value="{{ old('rating', $record->rating ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('rating')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<label class="flex items-center gap-2"><input type="checkbox" name="enabled" value="1" @checked(old('enabled', $record->enabled ?? true))><span>Enabled</span></label>
<div class="flex gap-3"><button class="rounded-lg bg-zinc-900 px-4 py-2 text-white dark:bg-white dark:text-zinc-900">Save</button><a href="{{ route('administration.testimonials.index') }}" class="rounded-lg border px-4 py-2">Cancel</a></div></form></div>
</x-layouts.app>
@@ -0,0 +1,5 @@
<x-layouts.app :title="__('Testimonials')">
<div class="space-y-6"><div class="flex items-center justify-between"><div><h1 class="text-2xl font-semibold">Testimonials</h1><p class="text-sm text-zinc-500">Manage testimonials content.</p></div><a href="{{ route('administration.testimonials.create') }}" class="rounded-lg bg-zinc-900 px-4 py-2 text-sm text-white dark:bg-white dark:text-zinc-900">Add new</a></div>
@if(session('status'))<div class="rounded-lg bg-emerald-50 p-3 text-emerald-800">{{ session('status') }}</div>@endif
<div class="overflow-hidden rounded-xl border border-zinc-200 bg-white dark:border-zinc-700 dark:bg-zinc-900"><table class="w-full text-sm"><thead class="bg-zinc-50 dark:bg-zinc-800"><tr><th class="px-4 py-3 text-left">Name</th><th class="px-4 py-3 text-left">Company</th><th class="px-4 py-3 text-left">Content</th><th class="px-4 py-3 text-right">Actions</th></tr></thead><tbody class="divide-y divide-zinc-200 dark:divide-zinc-800">@forelse($records as $record)<tr><td class="px-4 py-3">{{ is_array($record->name) ? json_encode($record->name) : Str::limit((string) $record->name, 70) }}</td><td class="px-4 py-3">{{ is_array($record->company) ? json_encode($record->company) : Str::limit((string) $record->company, 70) }}</td><td class="px-4 py-3">{{ is_array($record->content) ? json_encode($record->content) : Str::limit((string) $record->content, 70) }}</td><td class="px-4 py-3 text-right"><a class="mr-3 underline" href="{{ route('administration.testimonials.edit', $record) }}">Edit</a><form class="inline" method="POST" action="{{ route('administration.testimonials.destroy', $record) }}">@csrf @method('DELETE')<button class="text-red-600" onclick="return confirm('Delete this record?')">Delete</button></form></td></tr>@empty<tr><td colspan="4" class="px-4 py-10 text-center text-zinc-500">No records yet.</td></tr>@endforelse</tbody></table></div>{{ $records->links() }}</div>
</x-layouts.app>
+8
View File
@@ -0,0 +1,8 @@
<?php
use Illuminate\Support\Facades\Route;
use Modules\Testimonials\Http\Controllers\TestimonialController;
Route::middleware(['auth', 'verified'])->prefix('administration/testimonials')->name('administration.testimonials.')->group(function (): void {
Route::resource('/', TestimonialController::class)->parameters(['' => 'testimonial'])->except('show');
});
@@ -0,0 +1,5 @@
<?php
namespace Modules\Testimonials\Support;
final class ModuleInfo { public static function name(): string { return 'Testimonials'; } public static function nameLower(): string { return 'testimonials'; } }
@@ -0,0 +1,5 @@
<?php
use Illuminate\Support\Facades\Route;
it('registers the Testimonials administration route', function (): void { expect(Route::has('administration.testimonials.index'))->toBeTrue(); });
+20
View File
@@ -0,0 +1,20 @@
{
"name": "Testimonials",
"alias": "testimonials",
"version": "1.0.0",
"description": "Testimonials CMS module.",
"keywords": [
"cms",
"testimonials"
],
"priority": 29,
"providers": [
"Modules\\Testimonials\\Providers\\TestimonialsServiceProvider"
],
"aliases": {},
"files": [],
"requires": [
"Core",
"Administration"
]
}