Support the ongoing development of Laravel.io →
Laravel Requests

If a $request body was passed in with the categories 9,1,7 and I try to do the following it only will return the categories with ID 9

        $categories = implode('","',$request->categories);

        $statement = <<<'ENDSTATEMENT'
        SELECT 
            locations.name,
            locations.id,
            locations.lon,
            locations.lat,
            locations_categories.category_id as catId,
            locations_categories.location_id as locId,
            haversine(?,?,locations.lon,locations.lat) as distance
        FROM locations_categories, locations  
        WHERE locations.id = locations_categories.location_id
        AND locations_categories.category_id IN (?)  
        ORDER BY `distance` ASC
ENDSTATEMENT;

    $locations = DB::select($statement, array($request->lon, $request->lat, $categories));

But if if I was to do

AND locations_categories.category_id IN ("9","1","7")

Instead of passing the $categories variable in it returns all of the categories.

Why would it work for the hard coding but not passing the parameters in?

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.