Kailash Rajendhar
Kailash Rajendhar

Reputation: 25

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

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

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');

Upvotes: 0

Views: 15929

Answers (3)

Shreekanth
Shreekanth

Reputation: 859

Your customer id is coming string make it Array using explode.

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

Upvotes: 1

shalini
shalini

Reputation: 1290

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

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

Upvotes: 0

jedrzej.kurylo
jedrzej.kurylo

Reputation: 40899

You mixed up order of arguments you pass to update_customer method:

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

public static function update_customer($id,$data)

Upvotes: 1

Related Questions