Passing of parameter Laravel

Asked

Viewed 526 times

2

As step 2 or more variables on the route?

View

<a href="{{route('transferir.edit', [$destino->servidor->idservidor, $destino->setor])}}" class="btn btn-default btn-xs" role="button"><span class="glyphicon glyphicon-refresh"></span>Transferir</a>

Controller

public function edit($idservidor, $setorusuario)
{
    $servidor = Servidor::findOrFail($idservidor);

    $cargos = Cargo::orderBy('cargo')->pluck('cargo', 'idcargo');
    $setors = Setor::orderBy('setor')->pluck('setor', 'idsetor');

    return view('transferir.edit', compact('servidor','cargos','setors','setorusuario'));
}

Route

Route::resource('/transferir', 'TransferirController');
Route::get('/transferir/{idservidor}/{setor}', 'TransferirController@edit');
  • Hey, young man. You got it right?

  • Returns this error Type error: Too few Arguments to Function App Http Controllers Transferircontroller::Edit(), 1 passed and Exactly 2 expected

  • But you used what was suggested in the reply?

  • Yes, the url looks like this http://localhost:8000/download/7882/Edit? sector=CAD Weird.

  • Are you sure you used exactly the same? Notice that I edited and switched idServidor for idservidor.

  • I solved using its solution in the view and changing in the controller the function public Function Edit(request $sector, $idserver) ː }

Show 1 more comment

2 answers

1


Use an associative array - see documentation.

route('transferir.edit', ['idservidor' => $destino->servidor->idservidor, 
                          'setor' => $destino->setor]);

0

I do not know if I understood very well , but try:

route('transferir.edit', ['idservidor' => $destino->servidor->idservidor, 
                          'setor' => $destino->setor
                         ]);
  • 1

    Redundant with the previous answer

Browser other questions tagged

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