use Illuminate\Support\Facades\DB; function getPricesDrop($percentage) { $query = "SELECT * FROM products WHERE (price * $percentage / 100) >= price"; $result = DB::select($query); return $result; } $prices = getPricesDrop(10); print_r($prices); // returns an array of products with prices dropped by 10% or more
use Illuminate\Support\Facades\DB; function getPricesDrop($amount) { $query = "SELECT * FROM products WHERE price <= $amount"; $result = DB::select($query); return $result; } $prices = getPricesDrop(50); print_r($prices); // returns an array of products with prices dropped by $50 or moreIn both examples, we are using Laravel's DB facade to execute SQL queries to fetch data from a MySQL database. The getPricesDrop function takes in a parameter and returns an array of products that meet the specified criteria.