在表单中传递两个参数似乎无法弄清楚

时间:2015-03-24 14:43:28

标签: php forms laravel parameters

基本上我有一个事件ID和用户ID我需要在表单中传递存储...但是当我点击创建时它出现了

路线模式" / roles / {id} / {{id}}"不能引用变量名称" id"不止一次。

但是,如果我点击URL栏中的输入就可以了......所以不要确定这里发生了什么......这里的代码很有帮助。

路线档案

// POST Add Users Race
Route::post('racehistory/{event_id}/store/{user_id}/race/', 'racehistoryController@store'); 

// GET Current Races
Route::get('events/currentRace', 'racingeventController@viewCurrentRace');

// GET Users 
Route::get('events/{event_id}/users', 'racingeventController@users');

// GET Users with Group ID
Route::get('events/{event_id}/{group_id}', 'racingeventController@grouped');

// GET Add Users Race Form
Route::get('events/{event_id}/user/{user_id}/addrace', 'racingeventController@addUserRace');

// Add User to Event
Route::get('events/{event_id}/user/{user_id}', 'racingeventController@addUserToEvent');

// DELETE Remove User from Race Event
Route::get('events/{event_id}/delete/user/{user_id}', 'racingeventController@deleteUserToEvent');

// DELETE Race Event
Route::get('events/delete/{event_id}', 'racingeventController@destroy');

Route::resource('events', 'racingeventController');

表单视图

{{ Form::open(array('class' => 'form-horizontal', 'method' => 'post', 'action' => array('racehistoryController@store', $user->id, $event->id))) }}

Controller - racehistoryController

public function store($event_id, $user_id)
{
    $rules = array(
        'start_event'   => 'required',
        'end_event'     => 'required',
        'pool_type'     => 'required|max:3|min:3',
        'name'          => 'required|max:35|min:3',
        'location'      => 'required|max:35|min:3',
    );

    $validator = Validator::make(Input::all(), $rules);

    if ($validator->fails()) {
        return 'form works';
    }
}

1 个答案:

答案 0 :(得分:0)

  1. 为您的路线命名:
  2. Route::get(
        'racehistory/{event_id}/store/{user_id}/race/',
        ['as' => 'store', 'uses' => 'racehistoryControlle@store']
    ); 
    
    1. 修复Form::open()帮助:
    2. {{ 
          Form::open([
              'class' => 'form-horizontal', 
              'method' => 'post', 
              'route' => ['store', $user->id, $event->id]
          ]) 
      }}