You should do it this way:
$data = \DB::table("datos")->update(array("password" => bcrypt("password")));
That is, by using the facade DB
we access the name of the table
later we access the update()
method and pass it in the form of an associative array the column that we want to update and then the value that we want to generate, using the bcrypt()
method to encrypt it
IMPORTANT NOTE
bcrypt
will generate a data of alphanumeric type so it is important that the column on which you are going to execute the update supports this, being able to be a VARCHAR
otherwise you would get an error
UPDATE
If the update is not massive and you want to apply a where
to indicate which values should be updated; you must do the following
Here, for example, we tell you to only update if the id equals 2
$data = \DB::table("datos")->where('id', 2)->update(array("password" => bcrypt("password")));
If instead you want to run the update to a group of specific values but not all; then do the following
$data = \DB::table("datos")
->whereIn('id', [1, 3])
->update(array("password" => bcrypt("password")));
As notes I used the whereIn()
method where the first argument is the name of the column and later in the form of a comma separated array the range of values that will be modified or updated