Help with the error "Action {$ action} not defined." in Laravel

0

In my controller called DocenteController I have the function:

public function editarUsuario($id)
{.....}

In the routes file:

Route::resource('misvistas/docente', 'DocenteController');

and I send it to bring:

href="{{ URL::action('DocenteController@editarUsuario', $usuario->idusuario) }}"

I have other functions and those if you execute them (index, create, store, ...)

But with this function I get the error

  

"Action ... / TeacherController @ editUser not defined."

    
asked by Ricardo Garcia Olais 24.12.2017 в 04:21
source

1 answer

0

When you use

Route::resource('misvistas/docente', 'DocenteController');

It generates the following 7 routes by default:

+-----------+----------------------------------+------------------+------------------------------------------------------------------------+--------------+
| Method    | URI                              | Name             | Action                                                                 | Middleware   |
+-----------+----------------------------------+------------------+------------------------------------------------------------------------+--------------+
| POST      | misvistas/docente                | docente.store    | App\Http\Controllers\DocenteController@store                           | web          |
| GET|HEAD  | misvistas/docente                | docente.index    | App\Http\Controllers\DocenteController@index                           | web          |
| GET|HEAD  | misvistas/docente/create         | docente.create   | App\Http\Controllers\DocenteController@create                          | web          |
| PUT|PATCH | misvistas/docente/{docente}      | docente.update   | App\Http\Controllers\DocenteController@update                          | web          |
| GET|HEAD  | misvistas/docente/{docente}      | docente.show     | App\Http\Controllers\DocenteController@show                            | web          |
| DELETE    | misvistas/docente/{docente}      | docente.destroy  | App\Http\Controllers\DocenteController@destroy                         | web          |
| GET|HEAD  | misvistas/docente/{docente}/edit | docente.edit     | App\Http\Controllers\DocenteController@edit                            | web          |

You can check the available routes with the php artisan route:list command.

So DocenteController@editarUsuario is not a defined path validity, to be able to use it before you must create it, so that it points to the indicated method:

Route::get('misvistas/mi_ruta/{id}', 'DocenteController@editarUsuario');

or you can overwrite the existing route created with resource by matching the route ( misvistas/docente/{docente}/edit in this case) so that it points to the method and controller that we want.

Route::get('misvistas/docente/{docente}/edit', 'DocenteController@editarUsuario')->name('docente.edit');
    
answered by 24.12.2017 / 14:35
source