Translation eloquen consultation

0

Does anyone know how I can translate this query in eloquen?

update users set assignment = 'management' where user_ad = 'danielad';

I have three rows that belong to the user danielad, therefore I want in another of its fields which is called assignment is with the name management.

    
asked by zereft 22.10.2018 в 02:19
source

1 answer

0

first the use of the find () function only looks for the first value, it is designed to limit a single query.

the find function is designed to query the id that corresponds to the primary key you want to search

by which a query should be made in the user table where I look for the name of daniela and use a foreach

public function asignar(Request $request) 
{
$valor = $request->valor;//donde obtiene el dato "daniela"
$consulta=usuarios::where('name',$valor)->get();

foreach ($consulta as $value) {

  $userad = usuarios::findOrFail($value->id);//limite de un registro
  $userad->asignacion = $user->usuario_ad;
  $userad->save();
}

return redirect()->route('cuenta.tareas')->with('success','Registro actualizado satisfactoriamente');

} 
    
answered by 22.10.2018 в 05:08