douduocuima61392 2015-02-10 01:48
浏览 55
已采纳

在laravel中从数组插入表中

I am getting this array from the view

When i do return $BlogData['Tag'];

The result is

 ["1", "2"]

How can i insert this into each record i.e., a fresh entry in the table ?

S.No | Tag
   3 |  1
   4 |  2

Like the above given in the table

When i try

foreach ($BlogData['Tag'] as $x) 
        {
        echo $x;
        Tag::create($x);
        }

I am getting this error

message: "Argument 1 passed to Illuminate\Database\Eloquent\Model::create() must be of the type array, string given, 
  • 写回答

3条回答 默认 最新

  • dsovc00684 2015-02-10 02:10
    关注
    foreach ($BlogData['Tag'] as $x) 
    {
        Tag::create(['Tag' => $x]);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 为什么我按照电路图做出的仿真和实物都不能使用
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web