2016-05-27 157 views
0

大家早上好!如何添加單選按鈕

我對Laravel5中的單選按鈕有問題,現在我正確接收了名爲location1,location2,location3的單選按鈕數組。

$inputLoc= $request->input('location1'); 
var_dump($inputLoc); 

在這種情況下,我可以告訴0或1,根據對選定值,但現在我需要在這裏使用此位置。

for ($i=0; $i <$numbers; $i++) { 
    $extra= new Extra(); 
    $extra->description=$informacion[$i]; 
    $extra->pi_id=$pi[$i]; 
    $extra->location=0; 
    $extra->save(); 
} 

如何將位置數組發送到此位置?任何人都可以幫助我。

在數據庫中,我有一個數字0或1,但是我收到一個字符串串(1)「0」

很多的感謝!

回答

0

你可以使用'location'.$i並進行測試,如果它等於 「1」 或 「0」:

for ($i=0; $i <$numbers; $i++) { 
    $extra= new Extra(); 
    $extra->description=$informacion[$i]; 
    $extra->pi_id=$pi[$i]; 
    $extra->location=$request->input('location'.$i)=="1"?1:0; 
    $extra->save(); 
} 

希望這有助於。

+0

是整數0或1 – jc1992

+0

var_dump($ inputLoc)的輸出是什麼; –

+0

我收到一個字符串 – jc1992