laravel form post issue

2019-02-13 22:19发布

I am building a practice app with the Laravel framework I built a form in one of the views which is set to post to the same view itself but when I hit submit the form is posted however I do not get the desired output, I see the original view again.

Here is my view index.blade.php

@extends('master')

@section('container')

<div class="wrapper">

    {{ Form::open(array('url' => '/', 'method' => 'post')) }}
        {{ Form::text('url') }}
        {{ Form::text('valid') }}
        {{ Form::submit('shorten') }}
    {{ Form::close() }}

</div><!-- /wrapper -->

@stop 

and my routes.php

Route::get('/', function()
{
return View::make('index'); 
});

Route::post('/', function() 
{
return 'successfull';
});

What I've tried so far

  • I tried changing the post to a different view and it worked. However I want the form to post to the same view itself.

  • Instead of returning a string I tried to return make a view still it didn't work.

What am I doing wrong?

addendum

I see that when the form is making the post request I am getting a 301 MOVED PERMANENTLY HEADER

7条回答
倾城 Initia
2楼-- · 2019-02-13 23:00

The problem is with defualt slashed in Apache from 2.0.51 and heigher: http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryslash

The best solution if you do not want to change Apache config is to make the post in a different path:

GOOD:

Route::get('/', 
  ['as' => 'wizard', 'uses' => 'WizardController@create']);

Route::post('wizard-post', 
  ['as' => 'wizard_store', 'uses' => 'WizardController@store']);

NOT GOOD:

Route::get('/', 
  ['as' => 'wizard', 'uses' => 'WizardController@create']);

Route::post('/', 
  ['as' => 'wizard_store', 'uses' => 'WizardController@store']);
查看更多
登录 后发表回答