I have tried to translate this query to eloquen but until now I do not achieve it, does anyone know how I can do it?
update usuarios set asignacion='gestion' where id='8';
I have tried to translate this query to eloquen but until now I do not achieve it, does anyone know how I can do it?
update usuarios set asignacion='gestion' where id='8';
Assuming you have a User model declared in your project, it may be as follows
WITH HELP FROM ELOQUENT
$actualiza = Usuario::where('id', 8)
->update(['asignacion' => 'gestion']);
First we use the where
to find the record with id 8 in the table usuarios
and then through the update
method we pass an associative array, where the key is the name of the column and the value is the new value assigned to that column in that specific id
If you decide on this method and you have columns updated_at
in your table; then in your model you must declare the following
public $timestamps = false;
So that this column does not try to be the object of the update, this will only update the data of the columns that you indicate
WITH HELP OF THE QUERY BUILDER FLUENT
$actualiza = \DB::table('usuarios')
->where('id', 8)
->update(['asignacion' => 'gestion']);
We use the facade \ DB to invoke the table by its name by means of the table
method and then the remaining procedure is the same as the one used in Eloquent