title: Simple mutator screwing with SQL Query? - Laravel
body: <p>I want to be able to set the <code>user_id</code> via the <code>setUserIdAttribute</code> mutator but it won't work. The code works fine when I comment out the mutator. Below is my code and the resulting QueryException error. Please help!</p>
  
  <pre><code>// EventController.php
  public function store(Request $request)
  {
      Event::create([
        'name'=&gt;'myName',
        'user_id'=&gt;'1'
      ]);
      return 'Success!';
  }
  </code></pre>
  
  <hr>
  
  <pre><code>// Event.php
  class Event extends Model
  {
      protected $fillable = ['name', 'user_id'];
  
      // It works as expected if I comment this out.
      public function setUserIdAttribute($value)
      {
          // I know this code will run. If i do echo 'foo' it works.
          return '1';
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>// The migration file
  public function up()
  {
      Schema::create('events', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('name');
          $table-&gt;integer('user_id')-&gt;unsigned();
          $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');
          $table-&gt;timestamps();
      });
  }
  </code></pre>
  
  <hr>
  
  <pre><code>// The error I get
  SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into `events` (`name`, `updated_at`, `created_at`) values (myName, 2017-04-23 22:28:31, 2017-04-23 22:28:31))
  </code></pre>