Route not defined in form action in laravel 7 - laravel

View Form
Form
Routes
Routes
Route list
Route list
Controller
Reg controller
ERROR
Route [] not defined.

if you use resource
{{ route('student.store') }}
if you use ->name("student")
{{ route('student') }}

you have to read carefully the laravel documentation for routes
The form action attribute specifies where to send the form-data when a form is submitted.
so you simply direct submitted data as follow :
<form method="POST" action="student/store">
provided that your route like :
Route::post("student/store", "RegStudentsController#store");
or if you want to use the route:
Route::post("/student", "RegStudentsController#store")->name("student");
<form method="POST" action="{{ route('student') }}">
Update
as per your updated screen shoots the solution will be doing something like:
<form method="POST" action="{{ url('/student') }}">

Related

Methods (PUT, UPDATE, DELETE) that are not supported in some routes in Laravel

I'm having some problems about some routes that don't support certain methods.
// The PUT method is not supported for this route. Supported methods: POST.
Route::post('/action_create_hunter', [HunterController::class, 'store'])->name('action_create_hunter.store');
<form action="{{ url("action_create_hunter") }}" method="POST">
#csrf
.....
// The UPDATE method is not supported for this route. Supported methods: POST.
Route::post('/action_update_hunter/{id}', [HunterController::class, 'update'])->name('action_update_hunter.update');
<form action="{{ url("action_update_hunter/$hunter->id") }}" method="POST">
#csrf
.....
// The GET method is not supported for this route. Supported methods: DELETE.
Route::delete('/delete_hunter/{id}', [UserController::class, 'destroy'])->name('action_delete_hunter.destroy');
<i class="fa fa-trash"></i> Delete
You should define a hidden input with the Method name in this case , and for Laravel you can use #method , for example , If you want this be Put Method
The Route Will be
Route::put('/action_update_hunter/{id}', [HunterController::class, 'update'])->name('action_update_hunter.update');
And The form :
<form action="{{ url("action_update_hunter/$hunter->id") }}" method="POST">
#csrf
#method('put')
....
</form>
it's called Form Method Spoofing , check it in laravel docs For more information
https://laravel.com/docs/9.x/routing#form-method-spoofing

How can I customize the Log Out in Laravel 8 using Breeze?

I'm using tailwind, Laravel 8 and Breeze.
After installing Breeze I would like to customize (change size, color and text) the log out button but I have no idea how to do that.
Here is the code :
<form method="POST" action="{{ route('logout') }}">
#csrf
<x-dropdown-link :href="route('logout')"
onclick="event.preventDefault();
.closest('form').submit();">
{{ __('Log Out') }}
</x-dropdown-link>
</form>
and the auth.php
Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])
->middleware('auth')
->name('logout');
Thanks for your help
To begin, you should be aware that the dropdown-link is rendered using a component. When you alter the components, it may affect all pages that use that component.
You can modify that component in this file: resources/views/components/dropdown-link.blade.php
use this code in your blade file
Logout
#csrf
its on working

The POST method is not supported for this route. Supported methods: PUT. LARAVEL

I would like to send data with PUT method
However, this error happens.
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The POST method is not supported for this route. Supported methods: PUT.
I don't really understand why my code is not correct.
web.php
Route::get('/', function () {
return redirect('/home');
});
Auth::routes();
Route::put('/save_data', 'AbcController#saveData')->name('save_data');
view.blade.php
<form action="{{route('save_data')}}" method="POST">
#method('PUT')
#csrf
<input type = "hidden" name = "type" value ='stack' >
<div>
<button>post</button>
</div>
</form>
when it is changed
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
instead of
#method('PUT')
#csrf
It works well.
make sure to check First Another Route with Same Name
You can make POST route and dont need to put this after form tag #method('PUT')
CHange the Placement of the route before this Auth::routes();
use save_data in route instead of /save_data.
use {{url('save_data')}} in action instead of {{route('save_data')}}.
If you insist on using PUT you can change the form action to POST and
add a hidden method_field that has a value PUTand a hidden csrf field
(if you are using blade then you just need to add #csrf_field and {{
method_field('PUT') }}). This way the form would accept the request.
You can simply change the route and form method to POST. It will work
just fine since you are the one defining the route and not using the
resource group
after all this run artisan command
php artisan route:clear
Change:
<button>post</button>
to:
<button type="submit">post</button>

Send parameter by url in login laravel

Take the routes out of the auth and put them in web.php, I want to send a parameter through the url for the login but it throws me an error.
Route::get('login/{url}', 'Auth\LoginController#showLoginForm')->name('login');
Route::post('login', 'Auth\LoginController#login');
Route::post('logout', 'Auth\LoginController#logout')->name('logout');
ErrorException (E_ERROR)
Route [login/{url}] not defined. (View: C:\wamp64\www\portalmecanico_copia\resources\views\auth\login.blade.php)
Previous exceptions
Route [login/{url}] not defined. (0)
When using the route helper you are referencing the route name for the route. In this case the POST route doesn't have a name, so you should name it:
Route::post('login', ...)->name('post-login');
<form method="POST" action="{{ route('post-login') }}" aria-label="{{ __('Login') }}">
Your POST route isn't defining any route parameter so not sure what you want done with the url parameter from the GET route.
If you want to have the GET and POST route for login to take the same parameter you can do that without naming the POST route:
Route::get('login/{url}', ...)->name('login');
Route::post('login/{url}', ...);
<form method="POST" action="{{ route('login', ['url' => ...]) }}" aria-label="{{ __('Login') }}">
if you just want to resolve you error. you have to do this in your form action
<form method="get" action="{{ route('login', ['url' => 'specify the parameter here']) }}" aria-label="{{ __('Login') }}">
the {url} is just like variable.
but if you want to set your form method to post, you have to specified the route name, or you just can do with http://localhost/login

Laravel verfication.resend - The GET method is not supported for this route. Supported methods: POST

Odd question here. Im using the default Auth::routes(['verify' => true]); In Laravel 6. So I register ( Custom registration form ) and all works fine ( added to database etc ) then I am taken to the verification page where it has an email link to resend. When I click this I get:
The GET method is not supported for this route. Supported methods: POST.
The View has this named routed in the link route('verification.resend')
As you can see here. Verify resend is a POST route. So GET method is not allowed. So it should be a form Post instead.
If you are using blade something like this will get you there.
<form method="POST" action="{{ route('verification.resend')) }}">
</form>
Because in laravel 6+ they added this route as a post so you can do it by below code
<a onclick="event.preventDefault(); document.getElementById('email-form').submit();">{{ __('click here to request another') }}
</a>.
<form id="email-form" action="{{ route('verification.resend') }}" method="POST" style="display: none;">
#csrf
</form>

Resources