嗨,我正在使用Laravel黄昏 我有这样的输入作为数组..
<input type='text' name='debits[]' />
<input type='text' name='debits[]' />
如何使用
这样的数组键将值添加到第一个或第二个或特定输入中public function create(Browser $browser)
{
$browser
->select('journal_id',1)
->pause(100)
->click('.add-line')
->click('.add-line')
// code here to add 10 to first debits
// code here to add 15 to second debits
;
}
那真的很感谢..
答案 0 :(得分:1)
您可以这样做:
$names = collect([
'name1',
'name2'
]);
$this->browse(function ($browser) use ($names) {
$browser->visit('/names');
$names->each(function ($name, $key) {
$browser->type("array[$key]", $name);
});
$browser->press('Send');
});
根据您的代码,您可以执行以下操作:
public function create(Browser $browser)
{
$browser
->select('journal_id',1)
->pause(100)
->click('.add-line')
->click('.add-line');
$inputs = $browser->elements('input[name^="debits["]');
$inputs[0]->sendKeys(10); // code here to add 10 to first debits
$inputs[1]->sendKeys(15); // code here to add 15 to second debits
}
如果要使用for循环,可以执行以下操作:
foreach ($inputs as $input) {
$inputs = $browser->elements('input[name^="debits["]');
$input->sendKeys('100');
}