Laravel 5.4表单路由问题

时间:2017-06-23 08:28:43

标签: php laravel laravel-5.4

我有一个续订合同可以有多个设备的场景。我使用模态在续订的视图刀片中添加设备。问题是提交按钮不起作用。设备的“存储”功能位于合同控制器中,因此它会创建一个设备,然后将其与当前合同关联 我的路线:

    Route::post('/storeDevice', 'RenewalController@storeDevice')->name('renewals.storeDevice');

Route::get('/home', 'HomeController@index')->name('home');
Route::resource('clients', 'ClientController');
Route::resource('users', 'UserController');
Route::resource('projects', 'ProjectController');
Route::resource('supports', 'SupportController');
Route::resource('tests', 'TestController');
Route::resource('renewals', 'RenewalController');
Route::resource('devices', 'DeviceController');

我的模态

<div class="modal fade container" id="addDevice">
 {!! Form::open([ 'method'=>'POST', 'action' => ['RenewalController@storeDevice', $renewal] ]) !!}

<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">New Device</h4>
    </div>
    <div class="modal-body">
        <p>
            {!! Form::label('name', 'Name:', ['class' => 'control-label']) !!}
            {!! Form::text('name', null, ['class' => 'form-control']) !!}
        </p>
        <p>
            {!! Form::label('startDate', 'Warranty Start:', ['class' => 'control-label']) !!}
            {!! Form::date('startDate', null) !!}
            &nbsp
            {!! Form::label('endDate', 'Warranty End:', ['class' => 'control-label']) !!}
            {!! Form::date('endDate', null) !!}
        </p>
    </div>
    <div class="modal-footer">
        <button type="submit" class="btn btn-success"> Submit </button>
        <button type="button" class="btn btn-default" data-dismiss="modal"> Close </button>
    </div>
</div>

{!! Form::close() !!}
</div>

1 个答案:

答案 0 :(得分:0)

我有一些解决方案

  1. 使用{{ Form::submit('Submit ', array('class' => 'btn btn-success')) }}代替原始html按钮。或
  2. 将id添加到表单然后使用js单击提交按钮

    function form_submit() { document.getElementById("form_id").submit(); }

  3. 然后在onclick事件按钮中调用函数提交。 尝试这两个解决方案希望它能够运作