laravel 传递给 Illuminate\Database\Query\Builder::update() 的参数 1 必须是数组类型,给定的字符串,调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34175199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:47:53  来源:igfitidea点击:

Argument 1 passed to Illuminate\Database\Query\Builder::update() must be of the type array, string given, called in

phplaravellaravel-5

提问by Kailash Rajendhar

What im doing wrong..im getting this error..

我做错了什么..我收到这个错误..

Argument 1 passed to Illuminate\Database\Query\Builder::update() must be of the type array, string given, called in C:\xampp\htdocs\newlaravel\app\customer.php on line 33 and defined

传递给 Illuminate\Database\Query\Builder::update() 的参数 1 必须是数组类型,给定的字符串,在 C:\xampp\htdocs\newlaravel\app\customer.php 第 33 行调用并定义

Controller

控制器

public function siteadmin_customerupdate(Request $request,$id)
    {

        $cus_name = $request->input('first_name');
        //$facebook_id= $request->input('0');
        $cus_lname= $request->input('last_name');
        $cus_email= $request->input('email');


        $v=validator::make($request->all(),
                [

                ]
                );

        if($v->fails())
        {
            return redirect()->back()->withErrors($v->errors());
        }
        else
        {
            $data=array(

                'cus_name'=>$cus_name,
                //'facebook_id'=> $facebook_id,
                'cus_lname'=> $cus_lname,
                'cus_email'=> $cus_email,

            );

        }
         $return = customer::update_customer($data,$id);

Model

模型

public static function update_customer($id,$data)
    {

     DB::table('le_customer')->whereIn('cus_id', $id)->update($data);   
    }

route.php

路由文件

Route::get('siteadmin_editcustomer/{id}',   'SiteadminController@siteadmin_editcustomer'); 
   Route::post('siteadmin_customerupdate','SiteadminController@siteadmin_customerupdate');

回答by jedrzej.kurylo

You mixed up order of arguments you pass to update_customermethod:

您混淆了传递给update_customer方法的参数顺序:

customer::update_customer($data,$id);

public static function update_customer($id,$data)

回答by shalini

Mismatch argument passed and as per your statement first print variable you are passing to update ...

传递了不匹配的参数,根据您的语句,第一个打印变量传递给 update ...

As per error statement it must be array ..but string is coming

根据错误语句,它必须是数组 ..but string iscoming

回答by Shreekanth

Your customer id is coming string make it Arrayusing explode.

您的客户 ID 即将到来,使用expand将其设为 Array

DB::table('le_customer')->whereIn('cus_id', explode(',', $id))->update($data);