Send parameter by url in login laravel - 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

Related

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>

Route not defined in form action in laravel 7

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') }}">

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>

route is unable to run Controller

I'm new to laravel... created a route and given its a controller which has a method to update a database.. but once it reads the route the app is unable to get to the controller
Route::post('/workorder/store/third/{$id}',
[
'uses'=>'WorkOrdersController#storeThird',
'as'=>'workorder.store.third'
]);
//method in WorkOrderController
public function storeThird(Request $request,$id)
{
$this->validate($request,[
'address_region'=>'required|string',
'address_no'=>'required|string',
]);
$workorder = WorkOrder::find($id);
$workorder->address_region = $request->address_region;
$workorder->address_no = $request->address_no;
$workorder->save();
return view('third-workorder',compact('workorder'));
}
results in browser ...
in the address bar.. "http://localhost:8000/workorder/store/third/9"
and in the browser .."Sorry, the page you are looking for could not be found."
this.. view.blade looks like
<div class="modal" id="createThirdWorkshopModal">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST" action="{{ route('workorder.store.third',['id'=>$workorder->id]) }}" >
{{ csrf_field() }}
Navigating directly to http://localhost:8000/workorder/store/third/9 in your browser is a GET request, but you have the route defined as a route that handles a POST request. You need to submit something for that route to be "found":
<form method="POST" action="{{ url("/workorder/store/third/".$id) }}" ...>
...
</form>
or define the route as
Route::any("/workorder/store/third/{$id}", ...);
to handle this.
Note: ::any() handles all HTTP verbs (GET, POST, PUT, DELETE, etc.)
Router::post('/workorder/store/third/{$id}', WorkOrdersController#storeThird)->name('workorder.store.third');
and use:
<a href="{{route('workorder.store.third', $id)}}">
...
</a>

Laravel form won't PATCH, only POST - nested RESTfull Controllers, MethodNotAllowedHttpException

I am trying to allow users to edit their playlist. However, whenever I try to execute the PATCH request, I get the MethodNotAllowedHttpException error. (it is expecting a POST)
I have set up RESTful Resource Controllers:
Routes.php:
Route::resource('users', 'UsersController');
Route::resource('users.playlists', 'PlaylistsController');
This should give me access to: (as displayed through php artisan routes)
URI | Name | Action
PATCH users/{users}/playlists/{playlists} | users.playlists.update | PlaylistsController#update
However, when I try to execute the following form, I get the MethodNotAllowedHttpException error:
/users/testuser/playlists/1/edit
{{ Form::open(['route' => ['users.playlists.update', $playlist->id], 'method' => 'PATCH' ]) }}
{{ Form::text('title', $playlist->title) }}
{{ Form::close() }}
If I remove 'method'=> 'PATCH' I don't get an error, but it executes my public function store() and not my public function update()
In Laravel 5 and up:
<form method="POST" action="patchlink">
#method('patch')
. . .
</form>
Write {!! method_field('patch') !!} after form:
<form method="POST" action="patchlink">
{!! method_field('patch') !!}
. . .
</form>
Official documentation for helper function method_field()
Since html forms support only GET and POST you need to add an extra hidden field
to the form called _method in order to simulate a PATCH request
<input type="hidden" name="_method" value="PATCH">
As suggested by #Michael A in the comment above, send it as a POST
<form method="POST" action="patchlink">
<input type="hidden" name="_method" value="PATCH">
Worked for me.

Resources