我正在更新旧的Laravel应用和PHP,并且遇到了使用laravel-html的应用部分之一的问题。我猜这是因为从PHP 5.x-> 7.3更改“ +”的方式。有没有更干净,更好的方法来编写此代码?
[这是它在Laravel 5.0.38 / PHP 5.5中的工作方式:{!! Form::select('category', array('ALL'=>'(select)') + $categories, $category) !!}
我做了这个“修复”,在Laravel 5.1 / 7.3中可以使用:{!! Form::select('category', array_merge(array('ALL'=>'(select)'), json_decode(json_encode($categories), true)), $category) !!}
绝对没有必要同时通过$categories
和json_encode
来运行json_decode
。似乎正在执行此操作,以便将$categories
从集合转换为数组。如果是这种情况,您可以在集合上调用all()
以获取基础数组:
{!! Form::select('category', array_merge(['ALL'=>'(select)'], $categories->all()), $category) !!}