I can not correctly pass the arguments to the function that updates data in the database (Laravel)

0

I'm using Laravel 5.6 and I ran into a problem when I try to edit database records:

  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>
    
asked by anonymous 02.08.2018 / 15:10

1 answer

1

When you submit the form, the data comes with the Request class.

Ideally you would add a request, already with dependency injection, as the second parameter:

public function atualizar($id, Request $request){
    $conteudo = Conteudo::findOrFail($id);
    $corpo = $request->get('corpo');
    $conteudo->corpo = $corpo;
    $conteudo->save();
}

In this way, you can get any data that you add in the form.

Reference

    
02.08.2018 / 17:11