2016-04-29 59 views
0

我的控制器:存储阵列数据库列里 - laravel 5

public function store() 
{ 
    $links = array(); 
    $html = new \Htmldom('http://randomsite.org'); 

    foreach($html->find('a') as $a) 
    { 
     $links[] = $a->href; 
    } 

} 

和我有领域的数据库中的表称为结果:

id 
name 
url (i want to put the array here) 
desc 

我要的是多个记录的链接数

+0

序列化http://php.net/manual/en/function.serialize.php –

回答

2

如果我是对的。您需要解决方案将数据存储到数据库中。

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(); 
} 

在这里你遍历项中的每个阵列,并在表中插入多行

+0

谢谢你的人,你救我!我做一个foreach和$ result-> url并停下来,再次感谢你! – user0111001101

+0

欢迎您! –