arrays - "Array to string conversion"错误 Laravel - 尝试将数组保存到数据库

标签 arrays database laravel laravel-5

对不起,我是 Laravel 的新手,第一次尝试保存到数据库。我试图将数组保存到数据库,但出现错误“数组到字符串转换”。我尝试将迁移文件中的字符串值更改为其他选项,但出现了同样的错误。

Controller

    public function store(Request $request)
{   
    Myroutes::create([ //posting to acc table
        'start' => $request->start,
        'end' => $request->end,
        'waypoints' => $request->waypoints
    ]);

    return redirect('/');
}

迁移

 public function up()
{
    Schema::create('myroutes', function (Blueprint $table) {
        $table->increments('myroute_id');
        $table->integer('user_id');
        $table->string('start');
        $table->string('end');
        $table->string('waypoints');
        $table->timestamps();
    });
}

模型

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Myroutes extends Model
{
    protected $fillable = [
        'user_id',
        'start',
        'end',
        'waypoints'
    ];
}

查看

<div id="dynamicInput" class="form-group">
                    <label>Additional Destinations</label>
                    <input type="text" name="waypoints[]" class="form-control" autocomplete="on">
                </div>

数据库表

database-img

最佳答案

protected $casts = [
        'theme_setting' => 'array'
];

只需在类中的模型中使用转换

关于arrays - "Array to string conversion"错误 Laravel - 尝试将数组保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49985727/

相关文章:

php - Eloquent 查询来搜索两个表

arrays - 如何使用嵌套数组从散列中获取散列键?

arrays - 没有收到错误但没有看到输出

c - 动态分配指针数组到C中的结构

mysql - 使用带有内连接的 group by 时得到错误的总和

php - 拉维尔 |在 2 个表中搜索

mysql - 获取所有满足两种语言过滤条件的用户

vb.net - 比较两个字节数组的最快方法是什么?

android - Android中检查sqlite数据库是否存在时常失败

asp.net-mvc - 使用 ASP.NET MVC 在详细信息页面模板中显示数据库中的 byte[] 数组图像