Missing required Parameters for [Route: ] [URI: /{}/]

Asked

Viewed 972 times

4

I am trying to pass an update parameter, but it is giving error.

Controller

public function update(ColaborationFormRequest $request, $id
{
    $dataForm = $request->all();
    $colaboration = $this->colaboration->find($id);
    $update = $colaboration->update($dataForm);
    if ($update)
        return redirect()->route('colaboradores.index');
    else
        return redirect()->route('colaboradores.edit', $id)
                         ->with(['errors' => 'Falha ao editar']);
}

Route

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

View

{!! Form::open(['route' => 'colaboradores.update']) !!}
    <fieldset>
        <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', null, ['class'=>'form-control'])}}
                    </div>
                </div>
  • What error appears ? So without knowing which error appears to you help is a bit blind :) If you have the $id entering by the function your route should be /collaborators/{id} and not just /collaborators. However, if you are receiving a POST, why don’t you send the id around ?

  • Yeah, it’s true, anyway, I’m pretty sure that tip I give solves the problem.

  • Sorry. I edited the call form and it worked

2 answers

3

I changed the way to call the route and it worked

Of

{!! Form::open(['route' => 'colaboradores.update']) !!}

To

{{ Form::open(['route.name' => 'colaboradores.update']) }}

0

If you create the route without naming each action it creates automatico ex:

Route::resource('colaboradores', 'RH\ColaborationController');

To see the generated routes, in the terminal type:

php artisan route:list

And to call in form Collective

{!! Form::model(MODEL_DE_COLABORADOR,[
   'route' => ['colaboradores.update', ID_A_SER_ALTERADO],
   'method' => 'PUT'
])!!}

It will send by PUT to the controller, in the update method

Browser other questions tagged

You are not signed in. Login or sign up in order to post.