2016-11-29 79 views
1

我試過了其他帖子的解決方案數量,但仍然無法獲得它的工作。拉拉維爾4同一視圖上的兩種形式

我對頁面(視圖)兩種形式

{{ Form::open(array('action' => '[email protected]')) }} 
    ....// form fields 

    <button type="submit" class="btn btn-primary">Change</button> 
{{ Form::close() }}   
    <hr/> 
{{ Form::open(array('action' => '[email protected]')) }} 
    ....// second form fields 

    <button type="submit" class="btn btn-primary">Save Changes</button> 
{{ Form::close() }} 

然後在路線我

Route::post('/admin/preferences', ['uses' => '[email protected]', 'before' => 'csrf|admin']); 
Route::post('/admin/preferences', ['uses' => '[email protected]', 'before' => 'csrf|admin']); 

當我打在數據庫提交按鈕沒有任何變化。即使我提交第二個表單,頁面也會刷新,我會從FIRST表單獲得成功消息。

是否因爲這兩個帖子中的路徑相同?

更新:第一形式的輸入字段:

<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.'); 
} 

任何想法爲什麼不在數據庫中更新?

回答

3

路徑是級聯讀取的。由於兩條路徑具有相同的路徑,因此第一條路徑優先(找到條目,因此不需要進一步的路由查找)。

你應該將它們只不同的路徑拆分,例如:

Route::post('/admin/preferences/general', ['uses' => '[email protected]', 'before' => 'csrf|admin']); 
Route::post('/admin/preferences/shop', ['uses' => '[email protected]', 'before' => 'csrf|admin']); 
+1

非常感謝你,但第二種形式不提交數據庫的變化。我已經更新了我的問題。請你可以檢查? –

+0

這是一個完全不同的問題。複選框的行爲與其餘部分不同,如果未選中,則該字段不會根據請求到達。看到[這個問題](http://stackoverflow.com/questions/1809494/post-the-checkboxes-that-are-unchecked)它會有所幫助。讓我知道! – alariva

+0

但我總是有價值0或1.當它張貼我應該得到這個值,不是? –