【发布时间】:2016-11-29 22:31:46
【问题描述】:
我已经尝试了其他帖子中的许多解决方案,但仍然无法正常工作。
我在页面上有两个表单(视图)
{{ Form::open(array('action' => 'AdminController@shopMode')) }}
....// form fields
<button type="submit" class="btn btn-primary">Change</button>
{{ Form::close() }}
<hr/>
{{ Form::open(array('action' => 'AdminController@preferencesSubmit')) }}
....// second form fields
<button type="submit" class="btn btn-primary">Save Changes</button>
{{ Form::close() }}
然后在我的路线中
Route::post('/admin/preferences', ['uses' => 'AdminController@preferencesSubmit', 'before' => 'csrf|admin']);
Route::post('/admin/preferences', ['uses' => 'AdminController@shopMode', 'before' => 'csrf|admin']);
当我点击提交按钮时,数据库中没有任何变化。只是页面被刷新了,即使我提交了第二个表单,我也从第一个表单收到了成功消息。
是否因为两个帖子的路由中的 url 相同?
更新:第一个表单输入字段:
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" <?php if ($settings['preferences_shop_mode'] == 0){ ?> checked="checked" value="1"<?php }else{ ?> value="0" <?php } ?>>
在这里,我检查首选项是否 =0 以将值设置为 1 否则值 = 0。在源代码中,我看到该值为 =1,这是正确的,因为在数据库中我有 0
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked="checked" value="1">
这是控制器
public function shopMode() {
$preferences = Preferences::where('preferences_id', 1)->first();
if (!$preferences) {
App::abort(404);
}
Input::merge(array_map('trim', Input::all()));
$preferences->preferences_shop_mode = Input::get('onoffswitch');
$preferences->save();
return Redirect::to('/admin/preferences')->with('message', 'Shop mode changed successfully.');
}
知道为什么没有在数据库中更新吗?
【问题讨论】: