Return API Laravel json

1

I have a following problem, I made a API and it returns me a array :

"id": 1,
"email": "[email protected]",
"senha": "lucas123",
"created_at": "2018-02-15 16:48:12",
 "updated_at": "2018-02-15 16:48:12"'

I would like to only return 3 fields id , email and senha

Method:

public function index() 
{ 
    $contas = login::all(); 
    return response()->json(['contas'=>$contas], 200); 
}
    
asked by anonymous 06.03.2018 / 14:57

1 answer

3

Just select with the select method you need:

login::select('id', 'email', 'senha')->get();

Complete code:

public function index() 
{ 
    $contas = login::select('id', 'email', 'senha')->get();
    return response()->json(['contas'=>$contas], 200); 
}

Reference: Laravelle - Selects

    
06.03.2018 / 15:04