Laravel 5.8 method not supported error using register route - laravel

Lavavel 5.8 version. I'm getting route method error while using "register" Route.
<form action="{{url('register')}}" method="get" class="at-formtheme at-formcategories">
#csrf
EDIT
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::get('/','EmployeeController#index');
Route::post('signup-detail','EmployeeController#signup_detail');
Route::post('store-employee','EmployeeController#store_employee');
Route::post('store-interest','EmployeeController#store_interest');

Laravel uses a POST request for the default auth scaffolding. Change your form HTML tag to this:
<form action="{{url('register')}}" method="POST" class="at-formtheme at-formcategories">

I prefer to use named roads rather than the url (for greater maintainability)
<form action="{{route('register')}}" method="POST" class="at-formtheme at-formcategories">

Actually i was using two post method for submit forms (one post request send data on second form then submit) and use return back() method in my controller so the exception was through again and again.

Related

Difference b/w method="POST" and #method('PUT') in Laravel

I am use a form with attribute method="POST" to update the record in laravel. But updating of record is not working. Then after putting #method('PUT') inside the form, record updating is working fine.
I just want to know about #method('PUT') and when to use it in form of Laravel application.
Not Working
<form action="{{ route('student.update',$studentData->id) }}" method="POST">
...
</form>
Working Fine
<form action="{{ route('student.update',$studentData->id) }}" method="POST">
#csrf
#method('PUT')
...
</form>
The use of #method(...) is called form method spoofing in Laravel and is a requirement because HTML forms do no support PUT, PATCH or DELETE for the method attribute.
The value of the #method is sent as part of the form request and used by Laravel to determine how to process the form submission.
What does your web.php file look like ?
If you're using Route::resource('student', SomeController::class)
POST method will hit your student.create route, while PUT will hit your student.update route.
You can check your routes and their respective methods in detail by running php artisan route:list in your console
See if you are using resource routes for CRUD operation then it will include GET, POST, PUT and DELETE methods so when you are inserting data for first time using form that time you will use POST method and when you are doing update operation that time you have to use #method('put') because resource route will support only put method, you can update using POST also but you have to make separate route for that like we make general post route Route::post(...)

Laravel API route - exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException"

I'm making a Blog for school on my portfolio website, now I'm doing this in VueJS and Laravel and for this I need API routes.
Now I want to delete a comment with a specific ID but when I push the delete button it gives the error:
exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException"
The error is in the {routeCommentID} part of the next route:
Route::post('/deleteComment/{routeCommentID}', 'CommentController#delete');
What did I do wrong? Because when I remove that it works fine, but I need this part because I have to remove a comment with a specific ID.
Run php artisan route:list and check if route like '/deleteComment/{routeCommentID}' exists and whether you use that route in your Vue application.
for deleting a post it's better to use
Route::delete('/deleteComment/{id}', 'CommentController#delete');
and checkout your blade for deletion
it should be something like below
<form action={{ 'wanted route' }} method="post">
#csrf
#method('delete')
// your code
</form>

Is it possible to save form data through with Vue.js through Controller without Axios or asynchronous call?

I have a function in my controller that is used to store data. I am recreating my front end using Vue.js. As of now, I removed the current Laravel {{ Form: }} with Vue.js. Can I use same synchronous route without api to post the data? APIs are not ready and I cannot wait to validate my forms
Sure you can, all you need to do is to be aware that HTML does not have methods other than GET and POST. So, if you have PUT, DELETE and others, you're going to have to use the _method param trick.So, for example, when using the PUT http verb, you should create your form something like this:
<form method='POST'>
yourfields...
<input type="hidden" name="_method" value="PUT">
</form>
Other than that, it's pretty much calling the correct endpoints from your Vue application.

Laravel 'Route Not Defined' when route is clearly defined

I'm remaking the registration for my site, and have made a form that takes e-mail, password etc:
<form method="POST" class="etc" action="{{ route('register/blade/create') }}">
...
</form>
Then of course, my submit button in the form submits it and from routes in web.php:
Route::post('/register/basic/create', 'RegisterController#create');
However, every time I load this page, I get the following error:
I tried following others who had similar problems that posted on stack overflow, creating a named route, but that didn't seem to do the trick either. Any help is appreciated.
When you use named route route then you have to specify routes name in your routes/web.php file. Like this
routes/web.php
Route::post('/register/basic/create', 'RegisterController#create')->name('register');
In blade file
<form method="POST" class="etc" action="{{ route('register') }}">
...
</form>
Check details here https://laravel.com/docs/5.6/routing#named-routes
Sometimes the above error occurs when you have two routes with the same uri but different callbacks and different route name
For example
Route::post('update','PermissionController#update')->name('update_permission');`
Route::post('update','RoleController#update')->name('update_role');
The above routes update different resources but it will still return an error Route update_permission not defined or Route update_role not defined.
So the best thing to do is to use a different uri in each route so as to prevent conflict like this
Route::post('/role_permission/update','RoleController#update')->name('update_role');`
Route::post('/permission/update','PermissionController#update')->name('update_permission');
There is a possibility that you cashed the route so clear route cashe
php artisan route:clear
if you still not finding your route After clearing cache, then remove the route and re-write your route with different keywords, hope you will find the problem
you can use this command
php artisan optimize

CSRF error in laravel

I have a problem in Laravel . when over and over submit Form with post method and somtimes I get error and see expire error that related to CSRF
anybody knows how can I manage this error that display not in site and instead of redirect to any page else ?
Laravel makes it easy to protect your application from cross-site request forgery (CSRF).
Just add #csrf blade directive inside the form to avoid getting csrf token error.
<form method="POST" action="/profile">
#csrf
...
</form>
The directive puts something like this
<input type="hidden" name="_token" value="CzK6peomC6Pnnqdm4NsxpdGSH6v1evDnbN12oL" >
Read more about it in the laravel documentation here https://laravel.com/docs/5.6/csrf
Regarding the expiration of the token I think you might want to handle the error this way https://gist.github.com/jrmadsen67/bd0f9ad0ef1ed6bb594e
Also, there's a package which helps the forms keep awake.
https://github.com/GeneaLabs/laravel-caffeine
I hope that helps.
Laravel 5 using Blades templates, it's easy.
Add csrf toke in your blade file
{{ csrf_token() }}
If you are using Laravel 5.6 then you need to add something like this in your code of the form
#csrf
Check in detail about: CSRF Laravel

Resources