I'm trying to validate float in my laravel app. I'm using laravel validation and anything I try is not correct. I tried something like
$validator = Validator::make($request->all(), [
'packages.*.real_price' => 'required|regex:/^\d*(\.\d{2})?$/'
]
I tried with numeric, integer, and basically everything that I can find on the internet, but every time I receive error like:
TypeError: Argument 6 passed to App\Http\Controllers\ProductController::createPackageInfo() must be of the type float, string given
As you can see I'm giving string to test it. Any suggestions? I'm sending request like
{
"sku":"asd",
"slug":"admin@admin.com",
"category":"2",
"type":"accessory",
"product_info":[
{
"country":184,
"name":"asd",
"slug":"asd",
"description":"asd"
}
],
"packages":[
{
"country":98,
"name":"asd",
"slug":"asd",
"qty":"12",
"real_price":"123",
"sale_price":"asd",
"delivery_price":"123"
}
]
}
How am I calling this method?
try{
$createdPackageInfo = self::createPackageInfo($createdPackage, $country, $name, $slug, $real_price, $sale_price, $delivery_price, $image);
}catch (\Exception $e) {
Log::log('Something bad happened', 'POST', $e);
return response()->json(['response' => false, 'message' => 'Something went wrong with creating package info'], 400);
}
and function that I'm calling
private static function createPackageInfo(int $package_id, int $country_id, string $name, string $slug, float $real_price, float $sale_price, float $delivery_price, string $image)
{
$packageInfo = PackageInfo::create(['package_id' => $package_id, 'country_id' => $country_id, 'name' => $name, 'slug' => $slug, 'real_price' => $real_price, 'sale_price' => $sale_price, 'delivery_price' => $delivery_price, 'image' => $image]);
return $packageInfo->id;
}