Adding form action in html in laravel

2019-02-06 00:43发布

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:

10条回答
你好瞎i
2楼-- · 2019-02-06 01:08
{{ Form::open(array('action' => "WelcomeController@log_in")) }}
...
{{ Form::close() }}
查看更多
太酷不给撩
3楼-- · 2019-02-06 01:09

if you want to call controller from form action that time used following code:

<form action="{{ action('SchoolController@getSchool') }}"  >

Here SchoolController is a controller name and getSchool is a method name, you must use get or post before method name which should be same as in form tag.

查看更多
贪生不怕死
4楼-- · 2019-02-06 01:09

Your form is also missing '{{csrf_field()}}'

查看更多
女痞
5楼-- · 2019-02-06 01:10

You need to set a name to your Routes. Like this:


    Route::get('/','WelcomeController@home')->name('welcome.home');
    Route::post('/', array('as' => 'log_in', 'uses' => 'WelcomeController@log_in'))->name('welcome.log_in');
    Route::get('home', 'HomeController@index')->name('home.index');

I just put name on Routes that need this. In my case, to call from tag form at blade template. Like this:

<form action="{{ route('home.index') }}" >

Or, You can do this:

<form action="/" >
查看更多
登录 后发表回答