I have the following controller where I try to select all the customers of a user (The ones with 'user_id' equal to the 'id' of the authenticated user). I know how to do it in the following way, but as you can see it is not very efficient since it selects more records than necessary.
public function index() // Http/Controllers/CustomerController.php:17
{
$user_id = Auth::id(); // Get user ID
$customers = Customer::all()->where('user_id', $user_id); // Select all users and then filter by ID
return $this->showAll($customers, 200); // Return JSON response with response code
}