Q:

Laravel4 storing a collection

The question I have is about how to store a collection of models to a RESTful back end.
I'm using Backbone.js, and I'm considering to either: 

Use Async.js parallel method and post / put each model separately in a loop, after which a general callback method is triggered; 
Send a collection of objects to the back end, and use a database transaction to make sure that all models are properly saved with a single commit; 

The first method seems to cause a lot of overhead, because I have to make different calls to save the models. 
But when considering the second approach, Laravel4 does not by default allows to perform a post / put on a collection.  
What would be your preferred approach, and more importantly, why? 

A:

The second approach is definitely the way to go in my opinion, it reduces the latency and saves bandwidth if you use it with a large number of models since all the HTTP stuff (headers, etc) will be sent only once.
In your controller, use something like this (it may not work, I don't have access to any Laravel installation to test it) :
public function postCollection() {
    $collection = Input::get("collection");

    DB::transaction(function() {
        foreach ($collection as $data) {
            // In this example we assume it's a collection of users
            // Of course in a real app you would also do input validation
            $user = User::create(["name" => $data->name, "email" => $data->email]);
        }
    })

    // Example success response, will be automatically serialized to JSON
    return ["status" => "success"];
}

This loops over the collection element of your JSON input, which should be a list of models. Then it should obviously do validation and possibly other stuff. The whole loop is wrapped into a DB::transaction(), which will rollback everything if an exception occurs inside of it.

