Problem with a query to the database from Eloquent / PHP

0

I'm doing a SELECT query to my database, but I do not get what I want I've been reading the framework documentation, but I have not found the answer. This is what I have:

public function getUpdate(){

    1-$id = $_GET['id'];
    2-var_dump($id);
    3-$user = Users::query()->where('id', '=', $id)->get();
    4-var_dump($user);

    5-return $this->render('admin/update.twig', [
        'user' => $user
    ]);

}

In line 3 I am doing the query, but all the users of the database are returning me and I only need the user with the id that I asked for. I need help with that.

    
asked by Asdrubal Hernandez 06.07.2018 в 05:42
source

1 answer

3

If you're working laravel, just do this

// retorna null si no encuentra el registro
$user = Users::find($id); 

// Retorna una colección vacía en caso de no encontrar un registro.
$user = Users::where('id', $id)->get(); 
    
answered by 06.07.2018 / 05:56
source