How to update only 3 column value in laravel?

Member

by shyann , in category: PHP Frameworks , 10 months ago

How to update only 3 column value in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by gilbert , 10 months ago

@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.

Related Threads:

How to update a column with a null value in teradata?
How to update an exiting column on laravel?
How to update a column as foreign key on laravel?
How to update a json column in laravel?
How to decrement a column value in laravel?
How to access a column value in models in laravel?