samedi 3 juin 2017

Laravel 5.4: Storing the 'Where' clause in a variable

I want to write a dynamic update query in Laravel which accepts arguments and can be used in whole project.

Following is my Controller function:

public function editquery(Request $request)
    {

    $city_id   = $request->input('city_id');    
    $city_name = $request->input('city_name');   

    $tbl  = 'city';    
    $data = ['city_name'=>$city_name];
    $wher = ('city_id',1);

    General_model::editrecord($data,$wher,$tbl);

    return redirect()->action('Admin_controller@cities_page')->with('status','Record Updated Successfully!');;

    }

Below is my Model function:

public static function editrecord($data,$wher,$tbl)
    {
      return DB::table($tbl)->where($wher)->update($data);
    }

The only problem here is that I cannot store the value ('city_id',1) in the $wher variable. This is the screenshot of the error: link to the image file

Is there any other way to do this. Please Help.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2qO7xYR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire