updates for admin area

This commit is contained in:
Mark Gregory
2026-09-12 21:18:19 +01:00
parent ab3134de13
commit 5e2f4a1fa7
42 changed files with 894 additions and 210 deletions
+55
View File
@@ -0,0 +1,55 @@
@extends('layouts.admin')
@section('title', ($record ? 'Edit ' : 'Add ').$definition['singular'])
@section('page-title', $definition['title'])
@section('content')
<div class="page-heading admin-heading crud-heading">
<div><div class="eyebrow">{{ $record ? 'Edit record' : 'New record' }}</div><h1>{{ $record ? 'Edit '.$definition['singular'] : 'Add '.$definition['singular'] }}</h1><p>Complete the fields below and save your changes.</p></div>
<a class="toggle-button" href="{{ route('admin.resources.index', $resource) }}">← Back to {{ strtolower($definition['title']) }}</a>
</div>
@if($errors->any())
<div class="admin-error"><strong>Please correct the following:</strong><ul>@foreach($errors->all() as $error)<li>{{ $error }}</li>@endforeach</ul></div>
@endif
<div class="admin-card crud-form-card">
<form method="post" action="{{ $record ? route('admin.resources.update', [$resource, $record->getKey()]) : route('admin.resources.store', $resource) }}" class="crud-form">
@csrf
@if($record) @method('PUT') @endif
<div class="crud-form-grid">
@foreach($definition['fields'] as $name => $field)
@php
$raw = old($name);
if ($raw === null && $record) {
if ($name === 'role' && method_exists($record, 'getRoleNames')) $raw = $record->getRoleNames()->first();
elseif ($name === 'filters' && is_array($record->filters ?? null)) $raw = json_encode($record->filters, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
else $raw = data_get($record, $name);
}
if ($raw instanceof \Carbon\CarbonInterface && ($field['type'] ?? '') === 'datetime-local') $raw = $raw->format('Y-m-d\TH:i');
if ($raw instanceof \Carbon\CarbonInterface && ($field['type'] ?? '') === 'date') $raw = $raw->format('Y-m-d');
@endphp
@if(($field['type'] ?? 'text') === 'checkbox')
<label class="crud-check full-field"><input type="hidden" name="{{ $name }}" value="0"><input type="checkbox" name="{{ $name }}" value="1" @checked((bool)$raw)><span><strong>{{ $field['label'] }}</strong></span></label>
@else
<label class="crud-field {{ !empty($field['large']) || ($field['type'] ?? '') === 'textarea' ? 'full-field' : '' }}">
<span>{{ $field['label'] }}</span>
@if(($field['type'] ?? '') === 'select')
<select name="{{ $name }}">
@if(!empty($field['nullable']))<option value="">— None —</option>@endif
@php $selectOptions = isset($field['options']) ? ($options[$field['options']] ?? []) : ($field['values'] ?? []); @endphp
@foreach($selectOptions as $value => $label)<option value="{{ $value }}" @selected((string)$raw === (string)$value)>{{ $label }}</option>@endforeach
</select>
@elseif(($field['type'] ?? '') === 'textarea')
<textarea name="{{ $name }}" rows="{{ !empty($field['large']) ? 14 : 5 }}">{{ $raw }}</textarea>
@else
<input type="{{ $field['type'] ?? 'text' }}" name="{{ $name }}" value="{{ ($field['type'] ?? '') === 'password' ? '' : $raw }}" @if(isset($field['step'])) step="{{ $field['step'] }}" @endif @if(isset($field['min'])) min="{{ $field['min'] }}" @endif @if(isset($field['max'])) max="{{ $field['max'] }}" @endif>
@endif
@if(!empty($field['help']))<small>{{ $field['help'] }}</small>@endif
@error($name)<small class="field-error">{{ $message }}</small>@enderror
</label>
@endif
@endforeach
</div>
<div class="crud-form-actions"><button class="admin-button primary" type="submit">{{ $record ? 'Save changes' : 'Create '.$definition['singular'] }}</button><a class="toggle-button" href="{{ route('admin.resources.index', $resource) }}">Cancel</a></div>
</form>
</div>
@endsection
@@ -0,0 +1,62 @@
@extends('layouts.admin')
@section('title', $definition['title'])
@section('page-title', $definition['title'])
@section('content')
<div class="page-heading admin-heading crud-heading">
<div>
<div class="eyebrow">Management</div>
<h1>{{ $definition['title'] }}</h1>
<p>Create, edit and remove {{ strtolower($definition['title']) }} records.</p>
</div>
<div class="crud-heading-actions">
@if($resource === 'roles')<a class="toggle-button" href="{{ route('admin.resources.index', 'permissions') }}">Manage permissions</a>@endif
@if($resource === 'permissions')<a class="toggle-button" href="{{ route('admin.resources.index', 'roles') }}">Manage roles</a>@endif
@if($resource === 'settings')<form method="post" action="{{ route('admin.settings.clear-cache') }}">@csrf<button class="toggle-button" type="submit">Clear application cache</button></form>@endif
<a class="admin-button primary" href="{{ route('admin.resources.create', $resource) }}">+ Add {{ strtolower($definition['singular']) }}</a>
</div>
</div>
<div class="admin-card crud-toolbar">
<form method="get" action="{{ route('admin.resources.index', $resource) }}" class="crud-search">
<input type="search" name="q" value="{{ request('q') }}" placeholder="Search {{ strtolower($definition['title']) }}…">
<button class="admin-button" type="submit">Search</button>
@if(request('q'))<a class="toggle-button" href="{{ route('admin.resources.index', $resource) }}">Clear</a>@endif
</form>
<span class="record-count">{{ number_format($records->total()) }} records</span>
</div>
<div class="admin-card table-card">
<div class="responsive-table">
<table class="crud-table">
<thead><tr>@foreach($definition['columns'] as $label)<th>{{ $label }}</th>@endforeach<th class="actions-col">Actions</th></tr></thead>
<tbody>
@forelse($records as $record)
<tr>
@foreach($definition['columns'] as $path => $label)
@php
$value = $path === 'roles_text' ? $record->getRoleNames()->join(', ') : data_get($record, $path);
if ($value instanceof \Carbon\CarbonInterface) $value = $value->format('j M Y H:i');
elseif (is_bool($value)) $value = $value ? 'Yes' : 'No';
elseif (in_array($path, ['amount','total','deposit','price_from'], true) && $value !== null) $value = '£'.number_format((float)$value, 2);
@endphp
<td data-label="{{ $label }}">{{ filled($value) ? $value : '—' }}</td>
@endforeach
<td data-label="Actions">
<div class="row-actions">
<a class="toggle-button" href="{{ route('admin.resources.edit', [$resource, $record->getKey()]) }}">Edit</a>
<form method="post" action="{{ route('admin.resources.destroy', [$resource, $record->getKey()]) }}" onsubmit="return confirm('Delete this {{ strtolower($definition['singular']) }}? This cannot be undone.')">
@csrf @method('DELETE')
<button class="danger-button" type="submit">Delete</button>
</form>
</div>
</td>
</tr>
@empty
<tr><td colspan="{{ count($definition['columns']) + 1 }}"><div class="feature-empty"><div class="feature-icon">+</div><h2>No {{ strtolower($definition['title']) }} yet</h2><p>Create the first record to start managing this area.</p><a class="admin-button primary" href="{{ route('admin.resources.create', $resource) }}">Add {{ strtolower($definition['singular']) }}</a></div></td></tr>
@endforelse
</tbody>
</table>
</div>
</div>
<div class="crud-pagination">{{ $records->links() }}</div>
@endsection