2017-05-10 15 views
0
私はLaravel 5.1に5.0以上にLaravel 4からアップグレードした後、私はこのエラーを得た

:だから私はmacros.phpをcheckt :配列型でなければなりません、オブジェクトを指定して

Argument 2 passed to Collective\Html\HtmlBuilder::{closure}() must be of the type array, object given ... macros.php', '92', array('items' => object(Collection))) 

/** 
* 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() 
    )); 
+0

'$ view-> selectedOptionSalutation'には何が割り当てられていますか? – patricus

答えて

0

エラーは、あなたが渡しているitemsCollectionインスタンスであることを示しています。それは配列である必要があります。

したがって、DropdownHelper::getOptions()と呼んでいるどこでも、2番目のパラメータはCollectionであると推測しています。そのCollection->all()を呼び出して、基本配列を取得します。

0

私は

$selected = [] 

$selected = array() 

を交換すると思います

が動作するはずです。 laravel 4ではarray()関数を使用する必要がありましたが、新しいバージョンでは[]を使用できます。

+0

それは働かなかったが、ありがとう。 – blubbering

関連する問題