First thing ever, (by no means) create a route so this can disturb the others and cause problems, crash routes, etc... A basic example in creating this type of route would be with Route::post
(don’t need to use delete
only if it is a REST Web Api
, but for form use post
and get
that is enough.):
Example:
Route:
Route::post('pessoas/delete', 'PessoasController@delete');
Form:
<form action="/pessoas/delete" method="POST">
<input type="hidden" name="id" value="45" />
<button type="submit">Deletar</button>
</form>
Minimal example
An example (is a hint of how it could be) of routes for Controller
may follow the nomenclature of controller name, method name and vestments:
Route::get('pessoas/create', 'PessoasController@create'); // criar registro
Route::get('pessoas/edit/{id}', 'PessoasController@edit'); // editar registro
Route::get('pessoas/view/{id}', 'PessoasController@view'); // ver registro
Route::post('pessoas/store', 'PessoasController@store'); // salvar novo registro
Route::post('pessoas/update', 'PessoasController@update'); // atualizar registro
Route::post('pessoas/delete', 'PessoasController@delete'); // excluir registro
where the relationship is:
create
uses store
for record,
edit
uses update
for change registration, and
view
uses delete
for delete the record.
This can all be simplified, it can be changed, but, never use routes with a flag and only with it, right away this is a error, hinders the functioning of the site by limiting the site to have no simple route names.
Nice, but I’m having second thoughts about
csrf_field
is it possible to use without keys? because I am using angular– Lennon S. Bueno
I advise not to use without key. But, if really necessary, you can specify the routes that did not pass the CSRF check. https://laravel.com/docs/5.3/csrf#csrf-excluding-uris
– Carlos Fernandes
I meant the keys
{{
that conflict with the angular and generate nothing– Lennon S. Bueno
Which template engine you are using, Blade or Angularjs?
– Carlos Fernandes
I’m using only Angular 1 Carlos
– Lennon S. Bueno
You need to pass for the Angulajs o
csrf_field
somehow. The documentation itself recommends using themeta
tag in theheader
https://laravel.com/docs/5.3/csrf#csrf-x-csrf-token– Carlos Fernandes
Thanks I’ll study about helped me
– Lennon S. Bueno
Carlos figured out how to solve used
<?php echo csrf_field(); ?>
– Lennon S. Bueno