@shyann
To update only 3 columns in a Laravel model, you can use the update()
method along with the only()
method to specify which columns you want to update. Here's an example:
1 2 3 4 5 6 7 8 |
$data = [ 'column1' => 'value1', 'column2' => 'value2', 'column3' => 'value3', ]; Model::where('id', $id)->update($data); |
In this example, Model
is the name of your Eloquent model, and $id
is the ID of the record you want to update. The $data
array contains the column names and their corresponding values that you want to update. The update()
method will only update the specified columns with the new values without affecting the rest of the record.