From 8fee1d776d8f2f538968b1d761dfbbfd3e52ae27 Mon Sep 17 00:00:00 2001 From: Mateja Date: Sun, 1 Nov 2020 18:38:02 +0100 Subject: Editing signs buggy... --- app/Http/Controllers/SpecialCallsController.php | 26 +++++++++++++++ resources/views/pages/callsigns.blade.php | 2 +- resources/views/pages/editsign.blade.php | 42 +++++++++++++++++++++++++ routes/web.php | 5 +++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 resources/views/pages/editsign.blade.php diff --git a/app/Http/Controllers/SpecialCallsController.php b/app/Http/Controllers/SpecialCallsController.php index 073bf6e..3d6f2b9 100644 --- a/app/Http/Controllers/SpecialCallsController.php +++ b/app/Http/Controllers/SpecialCallsController.php @@ -131,4 +131,30 @@ class SpecialCallsController extends Controller { return Redirect::back(); } + + public function edit(Request $request, int $id) + { + $data = SpecialCall::findOrFail($id); + return view('pages.editsign', compact('data')); + } + + public function editForm(Request $request, int $id) + { + $rules = [ 'sign' => 'required' ]; + $messages = [ 'sign.required' => 'You need to provide a callsign!' ]; + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return Redirect::back() + ->withErrors($validator) + ->withInput(); + } + + $data = SpecialCall::findOrFail($id); + $data->sign = strtoupper($request->sign); + $data->description = $request->description; + $data->saveOrFail(); + + return Redirect::back()->with('statusE', 'Callsign edited.'); + } } diff --git a/resources/views/pages/callsigns.blade.php b/resources/views/pages/callsigns.blade.php index b4814bb..31d7ccf 100644 --- a/resources/views/pages/callsigns.blade.php +++ b/resources/views/pages/callsigns.blade.php @@ -12,7 +12,7 @@ @foreach ($data as $row) {{ $row->sign }} - + Edit @endforeach diff --git a/resources/views/pages/editsign.blade.php b/resources/views/pages/editsign.blade.php new file mode 100644 index 0000000..9f1f5ee --- /dev/null +++ b/resources/views/pages/editsign.blade.php @@ -0,0 +1,42 @@ +@extends('layouts.app') + +@section('title', 'Edit callsign') + +@section('navbar', View::make('inc.special_navbar')) + +@section('content') +

Edit Callsign:

+ @if (session('status')) +
+ {{ session('status') }} +
+ @endif +
+ @csrf +
+ + + @error('sign') +
{{ $message }}
+ @enderror +
+
+ + +
+
+ + +
+
+@endsection + +@section('scripts') + + +@endsection diff --git a/routes/web.php b/routes/web.php index 1d04dbf..1f9f47f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -46,6 +46,11 @@ Route::get('/special-calls/add', [SpecialCallsController::class, 'add'])->name(' Route::post('/special-calls/add', [SpecialCallsController::class, 'addForm'])->name('addSignForm') ->middleware(['auth']); +Route::get('/special-calls/edit/{id}', [SpecialCallsController::class, 'edit'])->name('edit') + ->middleware(['auth']); +Route::post('/special-calls/edit/{id}', [SpecialCallsController::class, 'editForm'])->name('editForm') + ->middleware(['auth']); + Route::get('/special-calls/reservations', [SpecialCallsController::class, 'reservations'])->name('reservations') ->middleware(['auth']); -- cgit v1.2.3