title: Laravel 4 Many to Many with Eloquent and checkboxes
body: <p>I'm trying to fix a problem with my Application using Laravel 4. The problem is about Eloquent and M:M relationship.</p>
  
  <p>Here's my situation:
  I've many users that can choose many services, for each service they can provide a dedicated price. In the database I've tables named "services","users" and "users_services".
  So at the moment I can save the services and the prices that every user choose BUT my problem is that I don't know how to retrive and show them to the user, I mean I don't know how to set up "checked" to the checkboxes of every selected service and the price for each one too.</p>
  
  <p>You can check the code here <a href="http://paste.laravel.com/Q3V" rel="nofollow">on Paste Laravel</a> for any fork. I paste it here too.</p>
  
  <pre><code>    &lt;?php
  
  class Service extends Eloquent {
  
      public static $rules = array();
  
      protected $guarded = array('id');
  
      /**
       * The database table used by the model.
       *
       * @var string
       */
      protected $table = 'services';
  
      /**
       * -------------------------------------
       * All Joins w/ other tables
       * -------------------------------------
       **/
      public function users()
      {
          return $this-&gt;belongsToMany('User','users_services','services_id','user_id');
      }
  }
  
  ......
  
  &lt;?php
  
  class User extends Eloquent {
  
      public static $rules = array();
  
      protected $guarded = array('id');
  
      /**
       * The database table used by the model.
       *
       * @var string
       */
      protected $table = 'users';
  
      /**
       * -------------------------------------
       * All Joins w/ other tables
       * -------------------------------------
       **/
      public function services()
          {
              return $this-&gt;belongsToMany('Service','users_services','user_id','service_id');
          }       
  }
  
  ................
  
  // Inside the controller 
  
  $services = Service::all();
  $this-&gt;layout-&gt;content = View::make('private.user.services')-&gt;with(compact('services'));
  
  ...............
  
  // The view
  @foreach($services as $service)
   &lt;div class="pull-left col-lg-6 service-container"&gt;
    &lt;div class="checkbox pull-left"&gt;
     &lt;label&gt;
      &lt;input type="checkbox" name="services[]" value="{{ $service-&gt;id }}"&gt;&lt;span&gt;{{ $service-&gt;name }}&lt;/span&gt;
     &lt;/label&gt;
    &lt;/div&gt;
    &lt;div class="input-group service-price pull-right"&gt;
    &lt;input type="number" min="0" name="prices[{{$service-&gt;id}}]" class="form-control pull-rigth" placeholder="0"&gt;
     &lt;span class="input-group-btn"&gt;
      &lt;button class="btn btn-default" type="button" disabled&gt;&lt;i class="icon-eur"&gt;&lt;/i&gt;&lt;/button&gt;
     &lt;/span&gt;
    &lt;/div&gt;
   &lt;/div&gt;
  @endforeach
  </code></pre>