throw new MethodNotAllowedHttpException ($ others); Laravel 5.7 Send HTML Form

0

When creating the update method, Laravel is giving the error.

protected function methodNotAllowed(array $others)
{
    throw new MethodNotAllowedHttpException($others);
}

View

{!! Form::model(array('route' => array('colaboradores.update', $colaboration->id), 'method' => 'put')) !!}
    <div class="card">
      <h5 class="card-header dark"><i class="fas fa-user"></i> Dados pessoais</h5>
        <div class="card-body">
          <div class="row">
            <div class="form-group col-md-6">
              {!! Form::label('nome', 'Nome: ') !!} {!! Form::text('nome', $colaboration->nome, ['class'=>'form-control'])!!}
            </div>
          </div>
      </div>
</div>

Controller

public function update(ColaborationFormRequest $request, $id)
{
    // Recupera todos os dados do formulário
    $dataForm = $request->all();

    //Recupera o colaborador para editar
    $colaboration = $this->colaboration->find($id);

    //Atualiza o colaborador
    $update = $colaboration->update($dataForm);

    //Verifica se editou o colaborador
    if ($update)
        return redirect()->route('colaboradores');
    else
        return redirect()->route('colaboradores.edit', $id)->with(['errors' => 'Falha ao editar']);
}

Route

Route::resource('/rh/colaboradores', 'RH\ColaborationController', [
'names' => [
    'index'     => 'colaboradores',
    'create'    => 'colaboradores.create',
    'edit'      => 'colaboradores.edit',
    'update'    => 'colaboradores.update',
]
]);

How do I resolve?

    
asked by anonymous 23.12.2018 / 19:53

1 answer

0

I was able to resolve the issue by changing the way Form opens

From

{!! Form::model(array('route' => array('colaboradores.update', $colaboration->id), 'method' => 'put')) !!}

By

{!! Form::model($colaboration, array('route' => array('colaboradores.update', $colaboration->id))) !!} @method('PUT')

Documentations:

link

link

Success to all!

    
24.12.2018 / 02:04