title: Is there a way to mass assign relations in laravel 5?
body: <p>I have two Model classes with a oneToMany relation like this</p>
  
  App\Car
  
  <pre><code>class Car extends Model
  {
  
      public $timestamps = true;
  
      protected $fillable = [
          'name',
          'price'
      ];
  
      public function parts ()
      {
          return $this-&gt;hasMany('App\Part');
      }
  
  }
  </code></pre>
  
  App\Part
  
  <pre><code>class Part extends Model
  {
  
      public $timestamps = false;
  
      protected $fillable = [
          'name',
          'price'
      ];
  
      public function car ()
      {
          return $this-&gt;belongsTo('App\Car');
      }
  
  }
  </code></pre>
  
  <p>The client makes a POST request with a JSON representing a Car with a nested Array of Parts</p>
  
  <pre><code>{
      "name": "Fiat Punto",
      "price": 15000,
      "parts": [
          {
              "name": "wheel",
              "price": 300
          },
          {
              "name": "engine",
              "price": 5000
          }
      ]
  }
  </code></pre>
  
  <p>Is there a way to save the Car model and create the relations in just one hit?</p>
  
  <p>I tried to do this in my controller but it doesn't work:</p>
  
  <pre><code>...
  public function store (Request $request) {
      $input = $request-&gt;all();
      Car::create($input);
  }
  ...
  </code></pre>
  
  <p>PS: I already know how to do the task with a <code>foreach</code> or <code>array_reduce</code>, just wondering if laravel could do that for me</p>
  
  <hr>
  
  <h3>-- Edit --</h3>
  
  <p>Here is how i implemented the controller right now:</p>
  
  <pre><code>...
  public function store (Request $request) {
      $input = $request-&gt;all();
      $car = Car::create($input);
      $parts = array_reduce(
          $input['parts'],
          function ($carry, $item) {
              array_push($carry, new Part($item));
              return $carry;
          },
          []
      );
      $car-&gt;parts()-&gt;saveMany($parts);
  }
  ...
  </code></pre>
  
  <p>Any improvement is welcome</p>