0
I am using Laravel 5.6 and came across a problem at the time I try to edit database records:
Step from the table that shows the data and options (edit, delete, etc.), to the edit page, and when I finish and step to the update function (below), an error is returned:
Too few Arguments to Function App Http Controllers Pagescontroller::update(), 0 passed and Exactly 2 expected
Function
public function atualizar($id, $corpo){
$conteudo = Conteudo::find($id);
$conteudo->corpo = $corpo;
$conteudo->save();
//return redirect()->route('');
}
Page edit.blade.php
<form method="post" action="{{action('PagesController@atualizar', $id)}}">
{{ csrf_field() }}
<div class="field">
<input type="hidden" value="{{ $conteudo['id'] }}"/>
<textarea class="12u$" name="corpo" id="corpo">{{$conteudo['corpo']}}</textarea>
</div>
<button type="submit" class="button small submit">Salvar
</form>
Thank you for the answer! But I still find the same problem: "Too few Arguments to Function App Http Controllers Pagescontroller::update(), 1 passed and Exactly 2 expected"
– Guilherme Abel
In the form action, you can use Laravel’s route() helper. For this, go to your route file, find the route in question and call the additional method:
->route('nome.da.sua.rota');
. In the form, do this:<form ... action="{{ route('nome.da.sua.rota', ['id' => $seu_id]) }}>
Reference: https://laravel.com/docs/5.6/routing#named-Routes– Matheus Picioli
When I access the variables through
$_POST['x']
, the code works. Function update:$conteudo = Conteudo::find($_POST['id']);
 $conteudo->corpo = $_POST['corpo'];
 $conteudo->save();
– Guilherme Abel
The following error is returned when using
->route('atualizar');
on the web.php: "Method Illuminate Routing Route::route does not exist."– Guilherme Abel
Comments the entire route here.
– Matheus Picioli
Route::get('inicio', 'PagesController@inicio')->name('inicio');
Route::get('mostrar', 'PagesController@mostrar'); 
Route::get('editar/{id}', 'PagesController@editar')->name('editar');
Route::post('atualizar', 'PagesController@atualizar')->route('atualizar');
– Guilherme Abel
The upgrade route has to be of the type
PUT
, and you missed to put the parameter {id} your route update as well. PS: With Laravel never use $_GET['any'], because the route work for the controller, does a whole security deal with the data.– Matheus Picioli