diff options
author | Mateja <mail@matejamaric.com> | 2020-11-01 23:55:13 +0100 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2020-11-01 23:55:13 +0100 |
commit | eb54ef5a24bc4af0749ad43ccffcbc1ae03aa4b6 (patch) | |
tree | bb9ff7cb37880577f664cff543e78b1bfc8dd1f5 | |
parent | 3c410d2bac3e338ab6d6045577819e292251c066 (diff) | |
download | yota-laravel-eb54ef5a24bc4af0749ad43ccffcbc1ae03aa4b6.tar.gz yota-laravel-eb54ef5a24bc4af0749ad43ccffcbc1ae03aa4b6.zip |
Special callsigns finished.
-rw-r--r-- | app/Http/Controllers/SpecialCallsController.php | 41 | ||||
-rw-r--r-- | resources/views/pages/callsigns.blade.php | 13 | ||||
-rw-r--r-- | resources/views/pages/editsign.blade.php | 2 | ||||
-rw-r--r-- | routes/web.php | 7 |
4 files changed, 43 insertions, 20 deletions
diff --git a/app/Http/Controllers/SpecialCallsController.php b/app/Http/Controllers/SpecialCallsController.php index 2c63c22..dd05810 100644 --- a/app/Http/Controllers/SpecialCallsController.php +++ b/app/Http/Controllers/SpecialCallsController.php @@ -36,7 +36,7 @@ class SpecialCallsController extends Controller $newcall->description = $request->description; $newcall->saveOrFail(); - return Redirect::back()->with('status', 'Callsign added.'); + return Redirect::back()->with('status', "Special callsign added."); } public function edit(Request $request, int $id) @@ -47,21 +47,34 @@ class SpecialCallsController extends Controller 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); + //dd($request->input('submit')); + if ($request->input('submit') == 'Edit callsign') { + $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(); - } + if ($validator->fails()) { + return Redirect::back() + ->withErrors($validator) + ->withInput(); + } - $data = SpecialCall::findOrFail($id); - $data->sign = strtoupper($request->sign); - $data->description = $request->description; - $data->saveOrFail(); + $data = SpecialCall::findOrFail($id); + $data->sign = strtoupper($request->sign); + $data->description = $request->description; + $data->saveOrFail(); + + return Redirect::route('addSign')->with('statusE', "Special callsign edited."); + } else return Redirect::route('addSign'); + } - return Redirect::back()->with('statusE', 'Callsign edited.'); + public function delete(Request $request, int $id) + { + //SpecialCall::findOrFail($id)->delete(); + $sign = SpecialCall::findOrFail($id); + $call = $sign->sign; + $sign->delete(); + return Redirect::back()->with('statusE', "Special callsign $call deleted."); } + } diff --git a/resources/views/pages/callsigns.blade.php b/resources/views/pages/callsigns.blade.php index 31d7ccf..6c795c4 100644 --- a/resources/views/pages/callsigns.blade.php +++ b/resources/views/pages/callsigns.blade.php @@ -5,19 +5,26 @@ @section('navbar', View::make('inc.special_navbar')) @section('content') + <h3>Callsigns Administration:</h3> + @if (session('statusE')) + <div class="alert alert-success"> + {{ session('statusE') }} + </div> + @endif @if (count($data) > 0) - <h3>Callsigns Administration:</h3> <div class="p-0 mt-3 col-lg-6 table-responsive"> <table class="table table-bordered"> @foreach ($data as $row) <tr> <td class="align-middle">{{ $row->sign }}</td> - <td><a href="{{ route('edit', $row->id) }}" class="btn btn-warning">Edit</a></td> - <td><button class="btn btn-danger">Delete</button></td> + <td><a href="{{ route('editSign', $row->id) }}" class="btn btn-warning">Edit</a></td> + <td><a href="{{ route('deleteSign', $row->id) }}" class="btn btn-danger">Delete</a></td> </tr> @endforeach </table> </div> + @else + <strong>There are currently no callsigns.</strong> @endif <h3 class="mt-4">Add Callsign:</h3> diff --git a/resources/views/pages/editsign.blade.php b/resources/views/pages/editsign.blade.php index 305bcee..0183441 100644 --- a/resources/views/pages/editsign.blade.php +++ b/resources/views/pages/editsign.blade.php @@ -11,7 +11,7 @@ {{ session('status') }} </div> @endif - <form action="{{ route('editForm', request()->route()->parameter('id')) }}" method="POST"> + <form action="{{ route('editSignForm', request()->route()->parameter('id')) }}" method="POST"> @csrf <div class="form-group"> <label for="Sign">Special Callsign:</label> diff --git a/routes/web.php b/routes/web.php index f743652..84e1b7e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -32,9 +32,12 @@ 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') +Route::get('/special-calls/edit/{id}', [SpecialCallsController::class, 'edit'])->name('editSign') ->middleware(['auth']); -Route::post('/special-calls/edit/{id}', [SpecialCallsController::class, 'editForm'])->name('editForm') +Route::post('/special-calls/edit/{id}', [SpecialCallsController::class, 'editForm'])->name('editSignForm') + ->middleware(['auth']); + +Route::get('/special-calls/delete/{id}', [SpecialCallsController::class, 'delete'])->name('deleteSign') ->middleware(['auth']); |