Laravel-ErrorException:数组到字符串的转换
在使用php artisan route:list时,我在Laravel的这段代码中遇到了一个问题Laravel-ErrorException:数组到字符串的转换,laravel,laravel-5,Laravel,Laravel 5,在使用php artisan route:list时,我在Laravel的这段代码中遇到了一个问题 ErrorException : Array to string conversion at /var/www/html/app/Http/Controllers/Merchant/CountryAreaController.php:312 308| } 309| } 310| if (!empty($
ErrorException : Array to string conversion
at /var/www/html/app/Http/Controllers/Merchant/CountryAreaController.php:312
308| }
309| }
310| if (!empty($request->rental_service)) {
311| $service[] = 2;
> 312| foreach ($request->get('rental_vehicle_type' . []) as $item) {
313| $area->VehicleType()->attach($item, ['service_type_id' => 2]);
314| }
315| $area->Package()->attach($request->rental_service, ['service_type_id' => 2]);
316| }
在错误的那一行,我改变了
foreach ($request->get('rental_vehicle_type' . []) as $item) {
到
array\u values()
解决了这个问题,我不知道为什么你为什么要选择租车类型。[]?为什么不干脆'rental_vehicle_type[]'
?老实说,这是一个非常老的项目,我现在不知道为什么在尝试第313行时要尝试其他错误检查代码Symfony\Component\Debug\Exception\fatalthrowable错误:语法错误,意外的'service_type_id'(T_字符串),预期','或''因此数组到字符串的转换
错误得到了修复,您还有一个额外的错误吗?是的,但我通过foreach($request->get('rental_vehicle_type')。数组值([])作为$item进行了修复。{出于某种原因,我添加了数组值(),所有的错误都得到了解决,谢谢!
foreach ($request->get('rental_vehicle_type' . array_values([])) as $item) {