Laravel Update Query


Laravel Update Query : Laravel Update Query Builder is used to update the existing records in a table.

update() is used to update the records in database table.


Syntax for Laravel Update Query

DB::table('table_name')
    ->where('column_name',value)
    ->update('data_array');

Where –

table_name : Name Of table

column_name: Name Of column and its corresponding value to match it.

data_array: Column Value pair to update the column value.

Laravel Update Query Example

$uid = 10;
$name = "John";
DB::table('users')->update
    ->where("id",$uid)
    ->update(array("name"=>$name));

The above Query will produce the following Result

UPDATE users set name = “John” WHERE id = ’10’;


Advertisements

Add Comment

📖 Read More