【问题标题】:store array inside database column - laravel 5在数据库列中存储数组 - laravel 5
【发布时间】:2016-08-25 03:44:13
【问题描述】:

我的控制器是:

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

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

}

我有一个名为 result 的数据库表,其中包含字段:

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

我想要的是多条记录作为数字链接

【问题讨论】:

标签: arrays database laravel store records


【解决方案1】:

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

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

在这里循环遍历每个项目数组并在表中插入多行

【讨论】:

  • 谢谢你,你救了我!我做了一个 foreach 和 $result->url 并停止,再次感谢您!
猜你喜欢
  • 2015-06-18
  • 2016-01-02
  • 1970-01-01
  • 2021-03-12
  • 1970-01-01
  • 1970-01-01
  • 2019-03-08
  • 1970-01-01
  • 2016-10-06
相关资源
最近更新 更多