56 lines
3.8 KiB
PHP
56 lines
3.8 KiB
PHP
@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
|