2017-09-20 72 views
0
 if ($request->input('workerRGroup.sAgent')) { 
      $worker->isAgent = 1; 
     } 

     if ($request->input('workerRGroup.supervisor')) { 
      $worker->isSupervisor = 1; 
     } 

     if ($request->input('workerRGroup.human')) { 
      $worker->isHuman = 1; 
     } 

     if ($request->input('workerRGroup.tech')) { 
      $worker->isTechnical = 1; 
     } 

那就是我已經嘗試了多選的值,laravel文檔說用點什麼,所以我用workerRGroup這是選擇的名稱和選擇選項的值。不能得到laravel

這是我的HTML

<label><b>Rank Group</b> 
     <select multiple name="workerRGroup[]"> 
      <option value="sAgent">Security Agent</option> 
      <option value="supervisor">Supervisor</option> 
      <option value="human">Human Resources</option> 
      <option value="tech">Technical</option> 
     </select> 
     </label> 

回答

0

因爲workerRGroup有作爲陣列狀['sAgent', 'supervisor']這樣的問題是,workerRGroup是一個關鍵,它有像['sAgent', 'supervisor']值,所以如果我們談論supervisor不是關鍵它的值,它的關鍵是1

這樣你就可以像$request->workerRGroup[1] //主管

訪問它,如果你要檢查它,所以你可以這樣做此

if (in_array('sAgent', $request->workerRGroup)) { 
    $worker->isAgent = 1; 
} 

    ....