数组到字符串的转换(SQL 使用 json_encode 方法时出错)

Array to string conversion (SQL Error while using json_encode method)

我收到数组到字符串的转换错误。 即使我尝试使用 serialize 和 json_encode 方法将数组转换为 string 。 但它没有用。我不知道这个问题是针对那个字符串还是其他变量,。 这是我的问题:

数组到字符串的转换

SQL:

insert into vehicledetails (vehicle_id, shortName, registration, vehicleType, vehiclemake, modelyear, documentType, dri_id, expDate, notiInterval, `user_id`, document, updated_at, created_a`)

values (w879847, 9e87sdf98, 9s8f7sd9f8, Car, sdjkfhskfh, NULL, Insurance, , , , 9266, ["dfusf9sf89.jpg","9sd8fsudfsd9.png"], 2019-08-07 13:17:41, 2019-08-07 13:17:41)

控制器:

        $request['user_id'] = Auth::user()->id;
                 $vehiDetails=$request->all();
                 $file = Input::file('file');

                if($file){
                    foreach($request->file('file') as $file) {
                        $exists = Storage::disk('spaces')->exists('FMSuploads/VehicleDoc/'.$file->getClientOriginalName());
                        if($exists){
                            \Session::flash('error', 'File name already exist');
                            return redirect()->back()->withInput();
                        }
                       else{
                        Storage::disk('spaces')->putFileAs('FMSuploads/VehicleDoc', request()->file, $file->getClientOriginalName(), 'public');
                         log::info('document uploaded successfullly');
                       }
                        $array[] = $file->getClientOriginalName();
                    }
                }else{
                    $vehiDetails['document'] = "";
                }
            }
                $array = json_encode($array);
                $vehiDetails['document'] = $array;
            VehicleDetails::create($vehiDetails);

模型页面。

class VehicleDetails extends Model
{
    protected $connection = 'mysql2';
        protected $table = 'vehicledetails';

     public $primaryKey = 'id';


    //public $timestamps = false;

    protected $fillable = array('user_id','vehicle_id','shortName','registration','morningTripStartTime','eveningTripStartTime','dri_id','vehicleType','vehiclemake','modelyear','documentType','document','expDate','notiInterval');


    protected $guarded = array();

}

循环外声明$docLink = ''; for 循环内部 $doclink .= $file->getClientOriginalName().','; 下面的 for 循环 $vehiDetails['document'] = $doclink; 希望这有助于解决