使用一个 post 请求在一个视图中显示两个或多个表单

two or more forms in one view using one post request

我暂时只有两种形式,它们都是post方法我试过这样解决

路线

Route::post('view', function(){
    if(Input::has('form1')){
        'NameController@method1';
    } elseif (Input::has('form2')){
       'NameController@method2';
    }
});

查看

{!! Form::open(array('url' => '/view')) !!}

    {!! Form::text('text', $trans->text)    !!}
    {!! Form::submit('Submit', array('name' => 'form1' )) !!}

{!! Form::close() !!}


{!! Form::open(array('url' => '/view')) !!}

    {!! Form::text('text', 'text')    !!}
    {!! Form::submit('Submit', array('name' => 'form2')) !!}

{!! Form::close() !!}

它抛出了这个错误

syntax error, unexpected ''ConfigurationController@title'    (T_CONSTANT_ENCAPSED_STRING) 

我更正了编码错误,但它不会像我希望的那样简单地执行 returns 空白屏幕,它不会循环槽控制器

我修改了代码(删除了return并关闭了路由)

您要做的是在 NameController

中创建一个方法 someMethodName
public function someMethodName()
{
    if(Input::has('form1')){
        $this->method1();
    } elseif (Input::has('form2')){
        $this->method2();
    }
}

然后用

替换所有路线内容
Route::post('view', 'NameController@someMethodName')