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