我从Laravel 4升级到5.0以上至5.1 Laravel后,我得到这个错误:升级到Laravel 5.1后:必须是类型的数组,对象给予
Argument 2 passed to Collective\Html\HtmlBuilder::{closure}() must be of the type array, object given ... macros.php', '92', array('items' => object(Collection)))
所以我checkt的macros.php
/**
* Render Dropdown Options
*/
HTML::macro('dropdownOptions', function(Collection $items, array selected, $withEmpty = true, $render = false)
{
$options = null;
/* jQuery Plugin 'choosen' needs an empty option as
* default selection */
if ($withEmpty)
{
$options = '<option></option>';
}
$items->each(function($item) use(&$options, $selected)
{
$options .= sprintf('<option %s value="%s">%s</option>',
(in_array($item->id, $selected)) ? 'selected="selected"' : '',
$item->id,
$item->name
);
});
if ($render)
{
echo $options;
}
return $options;
});
而且帮助我的文件:
use HTML;
use Illuminate\Database\Eloquent\Model;
class DropdownHelper
{
public static function getOptions($type, $selected = array())
{
return HTML::dropdownOptions(self::get(new $type), $selected);
}
public static function getGroupedOptions($type, $selected = array(), $childPropertyName = 'services')
{
return HTML::groupedDropdownOptions(self::get(new $type), $selected, $childPropertyName);
}
protected static function get(Model $model)
{
return $model::all();
}
}
但我不明白这一点,我查了composer.json和供应商还别名。一切看起来都不错。为什么我得到这个错误?
DropdownHelper :: getOptions:
$view
->with('optionsSalutation', DropdownHelper::getOptions(
DropdownEntityEnum::Salutations, $view->selectedOptionSalutation))
->nest('profileImageSection', 'customer.partials.profileimage', array('image' => $view->image));
UserProfileController:
$data = array_merge(Auth::user()->profile->toArray(), array(
'view' => 'customer.account.profile.private',
'type' => Auth::user()->getTypeId(),
'selectedOptionSalutation' => [Auth::user()->profile->getSalutationId()],
'image' => Auth::user()->profile->image,
'has_newsletter' => Auth::user()->getHasNewsletter()
));
'$ view-> selectedOptionSalutation'分配给了什么? – patricus