Laravel - How to call several methods passing the same route?

Asked

Viewed 455 times

-2

When I pass the two ends bugging the other and vice versa.

Example:

Route::get('/psicologo/editar/{psi_codigo}','PsicologoControlador@edit');
Route::get('/psicologo/editar/{psi_codigo}','ControladorMunicipioUf@ListaUfEditar');

How to solve?

  • There is no way to do this. You will have to call your other function through just one controller.

  • 1

    If they’re the same, the Laravel will prioritize a

2 answers

0

You cannot write the same route for two or more controller and métodos different. Each route that is configured is also unique within the project, but other than that it can write several different routes to the same controller and method, example:

It works:

Route::get('/psicologo/busca/{psi_codigo}','PsicologoControlador@edit');
Route::get('/psicologo/filter/{psi_codigo}','PsicologoControlador@edit');

because they are different routes pointed to the same controller and method.

Doesn’t work

Route::get('/psicologo/editar/{psi_codigo}','PsicologoControlador@edit');
Route::get('/psicologo/editar/{psi_codigo}','ControladorMunicipioUf@ListaUfEditar');

because the routes are equal (and should be unique) pointing to several controllers and methods.

In short: each route is unique in its project, where the repetition of the routes makes the project only work one of them.

  • My problem is this. when editing I call this route Route::get('/psicologo/edit/{psi_codigo}','Psychologocontroller@edit'); but I have a list of States(UF) that should be list in a select component. and this method that lists the states is in the Controllerstown Controllerscity whose method is Listaufedit. how do I call this method within the route I have reported above?

  • @user9078159 calls in method! now duplicate route can not. I explained the problem

  • I did it here. but still can’t find the public variable Function Edit($id) { $psi = Psicologo::find($id); if(isset($psi)){ Return view('editarPsicologo',Compact('psi')); $Listaufedit = Status::find(id$); Return('editarPsicologo',Compact('Listaufedit'); ; }

  • get!! I did it that way. */ public Function Edit($id) { $psi = Psicologo::find($id); $Listaufedit = Status:::all(); if(isset($psi)){ Return view('editarPsicologo',Compact('psi','Listaufedit'); } Return redirect('/psychologo'); }

-3

Route::get('/psicologo/editar/{psi_codigo}','PsicologoControlador@edit');
Route::get('/psicologo/editar/','ControladorMunicipioUf@ListaUfEditar');

Browser other questions tagged

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