edit form; refactoring form elements
This commit is contained in:
parent
a28017c475
commit
239e628b11
12 changed files with 146 additions and 60 deletions
|
@ -9,55 +9,46 @@
|
|||
|
||||
class JoinedController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Joined::class, 'joined');
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Joined::class, 'joined');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$collective = auth_collective();
|
||||
return view('admin.joined.index');
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin.joined.create')->with([
|
||||
'categories' => Category::all(),
|
||||
]);
|
||||
return view('admin.joined.create');
|
||||
}
|
||||
|
||||
public function store(StoreJoinedRequest $request)
|
||||
{
|
||||
$validated = $request->safe()->only([
|
||||
'categories',
|
||||
'url',
|
||||
'subject',
|
||||
'image',
|
||||
'approved',
|
||||
]);
|
||||
'categories',
|
||||
'url',
|
||||
'subject',
|
||||
'image',
|
||||
'approved',
|
||||
]);
|
||||
|
||||
Joined::store($validated);
|
||||
return redirect()->route('admin.joined.index')->with('success', 'Fanlisting added.');
|
||||
}
|
||||
Joined::store($validated);
|
||||
|
||||
public function show(Joined $joined)
|
||||
{
|
||||
//
|
||||
return redirect()->route('admin.joined.index')->with('success', 'Fanlisting added.');
|
||||
}
|
||||
|
||||
public function edit(Joined $joined)
|
||||
{
|
||||
//
|
||||
return view('admin.joined.edit')->with('joined', $joined);
|
||||
}
|
||||
|
||||
public function update(UpdateJoinedRequest $request, Joined $joined)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function destroy(Joined $joined)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ html {
|
|||
|
||||
body {
|
||||
font-family: "Imprima", sans-serif;
|
||||
font-size: 16px;
|
||||
font-size: 14px;
|
||||
background: rgb(243, 200, 255);
|
||||
background: linear-gradient(320deg, rgb(243, 200, 255) 0%, rgb(191, 191, 255) 100%);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ a:hover {
|
|||
|
||||
h1 {
|
||||
font-family: "Satisfy", serif;
|
||||
font-size: 46px;
|
||||
font-size: 44px;
|
||||
font-weight: normal;
|
||||
margin-left: 40px;
|
||||
margin-bottom: 10px;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
$f-main: 'Imprima', sans-serif;
|
||||
$f-title: 'Satisfy', serif;
|
||||
$f-size: 16px;
|
||||
$f-size: 14px;
|
||||
|
||||
$c-main: #7874ff;
|
||||
$c-main-light: color.scale($c-main, $lightness: 70%);
|
||||
|
|
|
@ -13,35 +13,13 @@
|
|||
@csrf
|
||||
|
||||
<fieldset class="form__fieldset">
|
||||
<label for="categories" class="form__label">Categories:</label>
|
||||
<x-admin.form.categories :categories="$categories" name="categories[]" id="categories"
|
||||
multiple required />
|
||||
@error('categories') <p class="form__error">{{ $message }}</p> @enderror
|
||||
<x-admin.form.categories name="categories[]" multiple required />
|
||||
<x-form.url name="url" required />
|
||||
<x-form.text name="subject" :label="'Subject:'" required />
|
||||
<x-form.file name="image" :accept="'image'" />
|
||||
<x-form.checkbox name="approved" :label="'Approved:'" />
|
||||
|
||||
<label for="url" class="form__label">URL:</label>
|
||||
<input type="url" id="url" name="url" value="{{ old('url') }}" class="form__input" required>
|
||||
@error('url') <p class="form__error">{{ $message }}</p> @enderror
|
||||
|
||||
<label for="subject" class="form__label">Subject:</label>
|
||||
<input type="text" id="subject" name="subject" value="{{ old('subject') }}"
|
||||
class="form__input" required>
|
||||
@error('subject') <p class="form__error">{{ $message }}</p> @enderror
|
||||
|
||||
<label for="image" class="form__label">Image:</label>
|
||||
<input type="file" id="image" name="image" value="{{ old('image') }}" accept="image/*"
|
||||
class="form__input--file">
|
||||
@error('image') <p class="form__error">{{ $message }}</p> @enderror
|
||||
|
||||
<div class="form__checkbox">
|
||||
<input type="checkbox" id="approved" name="approved" value="1"
|
||||
class="form__input--checkbox" @checked(old('approved'))>
|
||||
<label for="approved" class="form__label--checkbox">Approved</label>
|
||||
</div>
|
||||
|
||||
<div class="form__btns">
|
||||
<input type="submit" class="form__btn" value="Submit">
|
||||
<input type="reset" class="form__btn" value="Reset">
|
||||
</div>
|
||||
<x-form.buttons />
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
|
|
27
resources/views/admin/joined/edit.blade.php
Normal file
27
resources/views/admin/joined/edit.blade.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
@extends('admin.layout')
|
||||
|
||||
@section('pg-nav')
|
||||
<x-admin.nav :section="'joined'" />
|
||||
@endsection
|
||||
|
||||
@section('pg-title', 'Edit Joined')
|
||||
|
||||
@section('content')
|
||||
|
||||
<form action="{{ route('admin.joined.edit', $joined) }}" method="POST" autocomplete="off">
|
||||
@csrf
|
||||
@method('PATCH')
|
||||
|
||||
<fieldset class="form__fieldset">
|
||||
<x-admin.form.categories :prevCats="$joined->categories" name="categories[]" multiple
|
||||
required />
|
||||
<x-form.url name="url" :current="$joined->url" required />
|
||||
<x-form.text name="subject" :label="'Subject:'" :current="$joined->subject" required />
|
||||
<x-form.file name="image" :accept="'image'" />
|
||||
<x-form.checkbox name="approved" :label="'Approved:'" :current="$joined->approved" />
|
||||
|
||||
<x-form.buttons />
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
@endsection
|
|
@ -1,21 +1,33 @@
|
|||
{{-- expected attributes: name, id --}}
|
||||
@props(['categories', 'prevCats' => false])
|
||||
@props([
|
||||
'prevCats' => false,
|
||||
'labelClass' => '',
|
||||
'selectClass' => '',
|
||||
'errorClass' => '',
|
||||
])
|
||||
|
||||
@php
|
||||
use App\Models\Category;
|
||||
$categories = Category::all();
|
||||
|
||||
$id = rtrim($attributes['name'], '[]');
|
||||
|
||||
$selected = null;
|
||||
$name = rtrim($attributes['name'], '[]');
|
||||
if (old($name) != null) {
|
||||
$selected = collect(old($name));
|
||||
} else if ($prevCats) {
|
||||
$selected = $prevCats;
|
||||
$selected = $prevCats->pluck('id');
|
||||
}
|
||||
@endphp
|
||||
|
||||
<select {{ $attributes }} class="form__select" size="6">
|
||||
<label for="{{ $id }}" class="form__label {{ $labelClass }}">Categories:</label>
|
||||
<select id="{{ $id }}" {{ $attributes }} class="form__select {{ $selectClass }}" size="6">
|
||||
@foreach ($categories as $cat)
|
||||
<option value="{{ $cat->id }}"
|
||||
@if(isset($selected)) @selected($selected->search($cat->id) !== false) @endif>
|
||||
{{ $cat->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</select>
|
||||
@error($attributes['name']) <p class="form__error {{ $errorClass }}">{{ $message }}</p> @enderror
|
15
resources/views/components/form/buttons.blade.php
Normal file
15
resources/views/components/form/buttons.blade.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
@props([
|
||||
'divClass' => '',
|
||||
'submitClass' => '',
|
||||
'resetClass' => '',
|
||||
'btnClass' => '',
|
||||
'submitValue' => 'Submit',
|
||||
'resetValue' => 'Reset',
|
||||
])
|
||||
|
||||
<div class="form__btns {{ $divClass }}">
|
||||
<input type="submit" class="form__btn {{ $submitClass }} {{ $btnClass }}"
|
||||
value="{{ $submitValue }}">
|
||||
<input type="reset" class="form__btn {{ $resetClass }} {{ $btnClass }}"
|
||||
value="{{ $resetValue }}">
|
||||
</div>
|
20
resources/views/components/form/checkbox.blade.php
Normal file
20
resources/views/components/form/checkbox.blade.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
{{-- expected attributes: name --}}
|
||||
|
||||
@props([
|
||||
'divClass' => '',
|
||||
'value' => '1',
|
||||
'inputClass' => '',
|
||||
'current' => null,
|
||||
'labelClass' => '',
|
||||
'label'
|
||||
])
|
||||
|
||||
<div class="form__checkbox {{ $divClass }}">
|
||||
<input type="checkbox" id="{{ $attributes['id'] ?? $attributes['name'] }}" {{ $attributes }}
|
||||
value="{{ $value }}" class="form__input--checkbox {{ $inputClass }}"
|
||||
@checked(old($attributes['name'], $current))>
|
||||
<label for="{{ $attributes['id'] ?? $attributes['name'] }}"
|
||||
class="form__label--checkbox {{ $labelClass }}">
|
||||
{{ $label }}
|
||||
</label>
|
||||
</div>
|
15
resources/views/components/form/file.blade.php
Normal file
15
resources/views/components/form/file.blade.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
@props([
|
||||
'labelClass' => '',
|
||||
'label' => 'Image:',
|
||||
'accept' => 'image',
|
||||
'inputClass' => '',
|
||||
'formClass' => '',
|
||||
])
|
||||
|
||||
<label for="{{ $attributes['id'] ?? $attributes['name'] }}" class="form__label {{ $labelClass }}">
|
||||
{{ $label }}
|
||||
</label>
|
||||
<input type="file" id="{{ $attributes['id'] ?? $attributes['name'] }}" {{ $attributes }}
|
||||
value="{{ old($attributes['name']) }}" accept="{{ $accept }}/*"
|
||||
class="form__input--file {{ $inputClass }}">
|
||||
@error($attributes['name']) <p class="form__error {{ $formClass }}">{{ $message }}</p> @enderror
|
15
resources/views/components/form/text.blade.php
Normal file
15
resources/views/components/form/text.blade.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
{{-- expected attributes: name --}}
|
||||
@props([
|
||||
'labelClass' => '',
|
||||
'label',
|
||||
'current' => null,
|
||||
'inputClass' => '',
|
||||
'errorClass' => '',
|
||||
])
|
||||
|
||||
<label for="{{ $attributes['id'] ?? $attributes['name'] }}" class="form__label {{ $labelClass }}">
|
||||
{{ $label }}
|
||||
</label>
|
||||
<input type="text" id="{{ $attributes['id'] ?? $attributes['name'] }}" {{ $attributes }}
|
||||
value="{{ old($attributes['name'], $current) }}" class="form__input {{ $inputClass }}">
|
||||
@error($attributes['name']) <p class="form__error {{ $errorClass }}">{{ $message }}</p> @enderror
|
15
resources/views/components/form/url.blade.php
Normal file
15
resources/views/components/form/url.blade.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
{{-- expected attributes: name --}}
|
||||
|
||||
@props([
|
||||
'labelClass' => '',
|
||||
'label' => 'URL:',
|
||||
'current' => null,
|
||||
'inputClass' => '',
|
||||
'errorClass' => ''
|
||||
])
|
||||
|
||||
<label for="{{ $attributes['name'] }}" class="form__label {{ $labelClass }}">{{ $label }}</label>
|
||||
<input type="url" id="{{ $attributes['id'] ?? $attributes['name'] }}"
|
||||
value="{{ old($attributes['name'], $current) }}" class="form__input {{ $inputClass }}"
|
||||
{{ $attributes }}>
|
||||
@error($attributes['name']) <p class="form__error {{ $errorClass }}">{{ $message }}</p> @enderror
|
|
@ -38,8 +38,6 @@
|
|||
->name('admin.joined.create');
|
||||
Route::post('/fanatic/joined', [JoinedController::class, 'store'])
|
||||
->name('admin.joined.store');
|
||||
Route::get('/fanatic/joined/{joined}', [JoinedController::class, 'show'])
|
||||
->name('admin.joined.show');
|
||||
Route::get('/fanatic/joined/{joined}/edit', [JoinedController::class, 'edit'])
|
||||
->name('admin.joined.edit');
|
||||
Route::patch('/fanatic/joined/{joined}', [JoinedController::class, 'update'])
|
||||
|
|
Loading…
Reference in a new issue