Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Update Multiple Columns with QueryBuilder

I'm using Query builder, I successfully update na first column but on the second query the change doesnt happen, I already checked the view part the name of input and its correct. here is my code.

  DB::table('area')
        ->where('id', $request->get('area_id'))
        ->update(['island_group_id' => $request->get('island_group_id')],
                 ['region_id'       => $request->get('region_id')]);
        return 'test';
like image 888
Martney Acha Avatar asked Nov 28 '22 06:11

Martney Acha


2 Answers

DB::table('area')
    ->where('id', $request->get('area_id'))
    ->update([
             'island_group_id' => $request->get('island_group_id'),
             'region_id'       => $request->get('region_id')
            ]);
    return 'test';
like image 44
Kuldeep Mishra Avatar answered Dec 05 '22 19:12

Kuldeep Mishra


$updateDetails = [
    'island_group_id' => $request->get('island_group_id'),
    'region_id' => $request->get('region_id')
];

DB::table('area')
    ->where('id', $request->get('area_id'))
    ->update($updateDetails);
like image 129
Nikita Avatar answered Dec 05 '22 18:12

Nikita