将数组存储在数据库列中 - laravel 5
store array inside database column - laravel 5
我的控制器是:
public function store()
{
$links = array();
$html = new \Htmldom('http://randomsite.org');
foreach($html->find('a') as $a)
{
$links[] = $a->href;
}
}
我有数据库 table 调用结果字段:
id
name
url (i want to put the array here)
desc
我想要的是多条记录作为数字链接
如果我是对的。您需要将数据存储到数据库中的解决方案。
foreach($links as $link)
{
$result= new Result; //here Result is the model name for the table result
$result->id = $link[0]; //id
$event->name = $link[1]; //name
$event->url = $link[2]; //url
$event->desc = $link[3]; //desc
$event->save();
}
在这里,您遍历每个项目数组并在 table
中插入多行
我的控制器是:
public function store()
{
$links = array();
$html = new \Htmldom('http://randomsite.org');
foreach($html->find('a') as $a)
{
$links[] = $a->href;
}
}
我有数据库 table 调用结果字段:
id
name
url (i want to put the array here)
desc
我想要的是多条记录作为数字链接
如果我是对的。您需要将数据存储到数据库中的解决方案。
foreach($links as $link)
{
$result= new Result; //here Result is the model name for the table result
$result->id = $link[0]; //id
$event->name = $link[1]; //name
$event->url = $link[2]; //url
$event->desc = $link[3]; //desc
$event->save();
}
在这里,您遍历每个项目数组并在 table
中插入多行