I get this error when I create or edit a form, do you know if it comes from one of these views or from the Controller?
Missing required parameter for [Route: forms.show] [URI: forms/{form}] [Missing parameter: form]
Thankstrong texts for your help, this is my first post here.
Code below :
CONTROLLER FormsController:
public function create()
{
if (!Auth::check()) {
return redirect('login');
}
return view('forms.create');
}
public function show($id)
{
return view('forms.consult', ['forms' => Forms::findOrFail($id)]);
}
public function update(StoreFormsRequest $request, Forms $forms)
{
if (!Auth::check()) {
return redirect('login');
}
$request->validated();
$forms->update($request->input());
return redirect()->route('forms.show', ['forms' => $forms]);
}
public function edit($id)
{
if (!Auth::check()) {
return redirect('login');
}
return view('forms.edit', ['forms' => Forms::findOrFail($id)]);
}
VIEW create.blade.php:
<form action="{{ url('forms') }}" method="POST">
@csrf
...
<button class="btn btn-primary mb-1 mr-1" type="submit"> Ajouter </button>
</form>
edit.blade.php :
<form action="{{ url('forms', [$forms->id]) }}" method="POST">
@csrf
@method('PUT')
...
<button class="btn btn-primary mb-1 mr-1" type="submit"> Modifier </button>
</form>
ROUTE
web.php :
Route::get('/', [FormsController::class, 'index']);
Route::resource('forms', FormsController::class);
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/home', [App\Http\Controllers\FormsController::class, 'index'])->name('home');
CodePudding user response:
The problem is that your controller passes a paramater called forms
instead of form
. But your route is excpeting a form
parameter.
Change this:
return redirect()->route('forms.show', ['forms' => $forms]);
To this:
return redirect()->route('forms.show', ['form' => $forms]);
CodePudding user response:
Make sure you are passing 'form' parameter to the route. Use helper methods in view for example as
{{ route('forms.show', ['form' => 1]) }}