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' => 'Banners'];
@@ -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('banners', function (Blueprint $table): void { $table->id();
$table->string('title');
$table->text('content')->nullable();
$table->string('link_url')->nullable();
$table->string('position')->default('default');
$table->boolean('enabled')->default(true);
$table->timestamps(); $table->softDeletes(); }); }
public function down(): void { Schema::dropIfExists('banners'); }
};
@@ -0,0 +1,27 @@
<?php
namespace Modules\Banners\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Modules\Banners\Models\Banner;
final class BannerController extends Controller
{
public function index(): View { return view('banners::admin.index', ['records' => Banner::query()->latest()->paginate(20)]); }
public function create(): View { return view('banners::admin.form'); }
public function store(Request $request): RedirectResponse { $data = $request->validate(['title' => ['required', 'string', 'max:255'],
'content' => ['nullable', 'string'],
'link_url' => ['nullable', 'string'],
'position' => ['required', 'string', 'max:255'],
'enabled' => ['sometimes', 'boolean']]); $data['enabled'] = $request->boolean('enabled'); Banner::create($data); return redirect()->route('banners.index')->with('status', 'Banner created.'); }
public function edit(Banner $banner): View { return view('banners::admin.form', ['record' => $banner]); }
public function update(Request $request, Banner $banner): RedirectResponse { $data = $request->validate(['title' => ['required', 'string', 'max:255'],
'content' => ['nullable', 'string'],
'link_url' => ['nullable', 'string'],
'position' => ['required', 'string', 'max:255'],
'enabled' => ['sometimes', 'boolean']]); $data['enabled'] = $request->boolean('enabled'); $banner->update($data); return redirect()->route('banners.index')->with('status', 'Banner updated.'); }
public function destroy(Banner $banner): RedirectResponse { $banner->delete(); return back()->with('status', 'Banner deleted.'); }
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace Modules\Banners\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
final class Banner extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'banners';
protected $fillable = ['title', 'content', 'link_url', 'position', 'enabled'];
protected function casts(): array { return [
'enabled' => 'boolean'
]; }
}
@@ -0,0 +1,20 @@
<?php
namespace Modules\Banners\Providers;
use Illuminate\Support\ServiceProvider;
final class BannersServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->register(RouteServiceProvider::class);
$this->mergeConfigFrom(module_path('Banners', 'Config/config.php'), 'banners');
}
public function boot(): void
{
$this->loadMigrationsFrom(module_path('Banners', 'Database/Migrations'));
$this->loadViewsFrom(module_path('Banners', 'Resources/views'), 'banners');
}
}
@@ -0,0 +1,15 @@
<?php
namespace Modules\Banners\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('Banners', 'Routes/web.php')));
}
}
@@ -0,0 +1,9 @@
<x-layouts.app :title="isset($record) ? __('Edit Banner') : __('Create Banner')">
<div class="mx-auto max-w-4xl space-y-6"><div><h1 class="text-2xl font-semibold">{{ isset($record) ? 'Edit' : 'Create' }} Banner</h1></div><form method="POST" action="{{ isset($record) ? route('administration.banners.update', $record) : route('administration.banners.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">Title</label><input type="text" name="title" value="{{ old('title', $record->title ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('title')<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">Link Url</label><input type="text" name="link_url" value="{{ old('link_url', $record->link_url ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('link_url')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<div><label class="mb-1 block text-sm font-medium">Position</label><input type="text" name="position" value="{{ old('position', $record->position ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('position')<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.banners.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="__('Banners')">
<div class="space-y-6"><div class="flex items-center justify-between"><div><h1 class="text-2xl font-semibold">Banners</h1><p class="text-sm text-zinc-500">Manage banners content.</p></div><a href="{{ route('administration.banners.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">Title</th><th class="px-4 py-3 text-left">Content</th><th class="px-4 py-3 text-left">Link Url</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->title) ? json_encode($record->title) : Str::limit((string) $record->title, 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">{{ is_array($record->link_url) ? json_encode($record->link_url) : Str::limit((string) $record->link_url, 70) }}</td><td class="px-4 py-3 text-right"><a class="mr-3 underline" href="{{ route('administration.banners.edit', $record) }}">Edit</a><form class="inline" method="POST" action="{{ route('administration.banners.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\Banners\Http\Controllers\BannerController;
Route::middleware(['auth', 'verified'])->prefix('administration/banners')->name('administration.banners.')->group(function (): void {
Route::resource('/', BannerController::class)->parameters(['' => 'banner'])->except('show');
});
+5
View File
@@ -0,0 +1,5 @@
<?php
namespace Modules\Banners\Support;
final class ModuleInfo { public static function name(): string { return 'Banners'; } public static function nameLower(): string { return 'banners'; } }
@@ -0,0 +1,5 @@
<?php
use Illuminate\Support\Facades\Route;
it('registers the Banners administration route', function (): void { expect(Route::has('administration.banners.index'))->toBeTrue(); });
+20
View File
@@ -0,0 +1,20 @@
{
"name": "Banners",
"alias": "banners",
"version": "1.0.0",
"description": "Banners CMS module.",
"keywords": [
"cms",
"banners"
],
"priority": 26,
"providers": [
"Modules\\Banners\\Providers\\BannersServiceProvider"
],
"aliases": {},
"files": [],
"requires": [
"Core",
"Administration"
]
}