title: How To Cast Eloquent Pivot Parameters?
body: <p>I have the following Eloquent Models with relationships:</p>
  
  <pre><code>class Lead extends Model 
  {
      public function contacts() 
      {
          return $this-&gt;belongsToMany('App\Contact')
                      -&gt;withPivot('is_primary');
      }
  }
  
  class Contact extends Model 
  {
      public function leads() 
      {
          return $this-&gt;belongsToMany('App\Lead')
                      -&gt;withPivot('is_primary');
      }
  }
  </code></pre>
  
  <p>The pivot table contains an additional param (<code>is_primary</code>) that marks a relationship as the primary. Currently, I see returns like this when I query for a contact:</p>
  
  <pre><code>{
      "id": 565,
      "leads": [
          {
              "id": 349,
               "pivot": {
                  "contact_id": "565",
                  "lead_id": "349",
                  "is_primary": "0"
               }
          }
      ]
  }
  </code></pre>
  
  <p>Is there a way to cast the <code>is_primary</code> in that to a boolean? I've tried adding it to the <code>$casts</code> array of both models but that did not change anything.</p>