在Laravel 4中使用对象数组

I'm trying to use an array of object between a controller and a view file in Laravel 4.

Controller code :

public function addItem()
{
    $file = Input::file('file'); // your file upload input field in the form should be named 'file'

    $destinationPath = 'uploads/'.str_random(8);
    $filename = $file->getClientOriginalName();
    //$extension =$file->getClientOriginalExtension(); //if you need extension of the file
    $uploadSuccess = Input::file('file')->move($destinationPath, $filename);        

    $item               = new Item();
    $item->name         = Input::get('item_name');
    $item->description  = Input::get('item_description');  
    $item->price        = Input::get('item_price');  
    $item->picture_url  = $destinationPath ."/". $filename;
    $item->id_sale      = Session::get('current_sale')->id;
    $item->save();

    $array_items = Session::get('current_items');
    //$array_items = array($item);
    array_push($array_items, $item);

    //$array_items = array_add($array_items, $item->id, $item);
    Session::put('current_items', $array_items);        

    //print_r(Session::get('current_items'));exit();

    return Redirect::to('create_sale_add_item');
}

View code "create_sale_add_item" here:

@foreach(Session::get('current_items') as $i)
<div class="row">
    <div class="span2"><h2><img src="{{ $i->picture_url }}" style="width: 200px; height: 150px;"></h2></div>
    <div class="span10">
        <p>Nom : {{ $i->name }}</p>
        <p>Description : {{ $i->description }}</p>
        <p>Prix : {{ $i->price }}</p>
    </div>
</div>
@endforeach

But when I display the corresponding page, I have this error:

ErrorException

main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition &quot;Item&quot; of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition

Does someone has already see this problem?

I suspect the problem lies in the interaction of Blade's @foreach and the Session class. I think the Session class is unserializing objects every time the loop runs and that seems perilous.

Try

$items = Session::get('current_items');
@foreach ($items as $i)...

Just autoload the class using:

composer dump-autoload -o

Also you don't need to use

Session::put('current_items',$array_items)

A neater way would be:

return Redirect::to('create_sale_add_item')->with('current_items',$array_items);

Also in your view:

@if(Session::has('current_items'))

   @foreach(Session::get('current_items') as $i)
    ...
   @endforeach

@endif