-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete not working on minimal install of laravel-code-generator #181
Comments
What happens when you try to delete a model? Do you get an error? you may want to look at Laravel’s logs for more clues. |
I forgot to include the site: https://rlevy.assessmentengineering.com/colors Get no error: it returns to https://rlevy.assessmentengineering.com/colors/color/2 LOGS |
Probably, because just a js call is being done, and not action triggered on the database?! FILE: resources/laravel-code-generator/templates/default/index.blade.stub Line 66: |
Hello there, |
Environment:
Description:
Vanilla build: Only Laravel/Crestapps/Mysql
Steps/Commands To Reproduce:
MYSQL:
CREATE TABLE
colors
(id
int(11) NOT NULL AUTO_INCREMENT,color
varchar(45) DEFAULT NULL,is_primary
int(11) DEFAULT NULL,PRIMARY KEY (
id
)) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
app.blade.php
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"> </script> <title>{{ config('app.name', 'Laravel') }}</title>artisan
php artisan create:scaffold Color --table-exists
Use site to do CRUD
Delete does not delete
Content Of The Resource-File:
ROUTE
Route::group([
'prefix' => 'colors',
], function () {
Route::get('/', [ColorsController::class, 'index'])
->name('colors.color.index');
Route::get('/create', [ColorsController::class, 'create'])
->name('colors.color.create');
Route::get('/show/{color}',[ColorsController::class, 'show'])
->name('colors.color.show')->where('id', '[0-9]+');
Route::get('/{color}/edit',[ColorsController::class, 'edit'])
->name('colors.color.edit')->where('id', '[0-9]+');
Route::post('/', [ColorsController::class, 'store'])
->name('colors.color.store');
Route::put('color/{color}', [ColorsController::class, 'update'])
->name('colors.color.update')->where('id', '[0-9]+');
Route::delete('/color/{color}',[ColorsController::class, 'index'])
->name('colors.color.destroy')->where('id', '[0-9]+');
});
INDEX.BLADE.PHP form element
COLORS CONTROLLER
getData($request); Color::create($data); return redirect()->route('colors.color.index') ->with('success_message', 'Color was successfully added.'); } catch (Exception $exception) { return back()->withInput() ->withErrors(['unexpected_error' => 'Unexpected error occurred while trying to process your request.']); } } /** * Display the specified color. * * @param int $id * * @return Illuminate\View\View */ public function show($id) { $color = Color::findOrFail($id); return view('colors.show', compact('color')); } /** * Show the form for editing the specified color. * * @param int $id * * @return Illuminate\View\View */ public function edit($id) { $color = Color::findOrFail($id); return view('colors.edit', compact('color')); } /** * Update the specified color in the storage. * * @param int $id * @param Illuminate\Http\Request $request * * @return Illuminate\Http\RedirectResponse | Illuminate\Routing\Redirector */ public function update($id, Request $request) { try { $data = $this->getData($request); $color = Color::findOrFail($id); $color->update($data); return redirect()->route('colors.color.index') ->with('success_message', 'Color was successfully updated.'); } catch (Exception $exception) { return back()->withInput() ->withErrors(['unexpected_error' => 'Unexpected error occurred while trying to process your request.']); } } /** * Remove the specified color from the storage. * * @param int $id * * @return Illuminate\Http\RedirectResponse | Illuminate\Routing\Redirector */ public function destroy($id) { try { $color = Color::findOrFail($id); $color->delete(); return redirect()->route('colors.color.index') ->with('success_message', 'Color was successfully deleted.'); } catch (Exception $exception) { return back()->withInput() ->withErrors(['unexpected_error' => 'Unexpected error occurred while trying to process your request.']); } } /** * Get the request's data from the request. * * @param Illuminate\Http\Request\Request $request * @return array */ protected function getData(Request $request) { $rules = [ 'color' => 'nullable|string|min:0|max:45', ]; $data = $request->validate($rules); return $data; } }The text was updated successfully, but these errors were encountered: