I am unable to pass url in views html form action tag.
<form method="post" action="??what to write here??" accept-charset="UTF-8">
I want to set it's action to WelcomeController@log_in
function in WelcomeController
file in controllers.
Here are my routes:
Route::get('/','WelcomeController@home');
Route::post('/', array('as' => 'log_in', 'uses' => 'WelcomeController@log_in'));
Route::get('home', 'HomeController@index');
After submitting it keeps the same url
http://localhost:8000/
And the main error line
Whoops, looks like something went wrong.
After that there is 1/1 TokenMismatchException in compiled.php line 2440:
Form Post Action :
Change your Route : In Routes -> Web.php
I wanted to store a post in my application, so I created a controller of posts (PostsController) with the resources included:
php artisan make:controller PostsController --resource
The controller was created with all the methods needed to do a CRUD app, then I added the following code to the
web.php
in the routes folder :Route::resource('posts', 'PostsController');
I solved the form action problem by doing this:
php artisan route:list
posts.store
action="{{route('posts.store')}}"
instead ofaction="??what to write here??"
Use
action="{{ action('WelcomeController@log_in') }}"
however TokenMismatchException means that you are missing a CSRF token in your form.
You can add this by using
<input name="_token" type="hidden" value="{{ csrf_token() }}">
1) In Laravel 5 , form helper is removed .You need to first install laravel collective .
Refer link: https://laravelcollective.com/docs/5.1/html
OR
2) For laravel 4, form helper is already there
You can use the
action()
helper to generate an URL to your route:Note that the Laravel 5 default installation already comes with views and controllers for the whole authentication process. Just go to
/home
on a fresh install and you should get redirected to a login page.Also make sure to read the Authentication section in the docs
The error you're getting now (
TokenMismatchException
) is because Laravel has CSRF protection out of the boxTo make use of it (and make the error go away) add a hidden field to your form:
Alternatively you can also disable CSRF protection by removing
'App\Http\Middleware\VerifyCsrfToken'
from the$middleware
array inapp/Http/Kernel.php
The following should work.