简单的mutator与SQL Query拧紧? - Laravel

I want to be able to set the user_id via the setUserIdAttribute 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!

// EventController.php
public function store(Request $request)
{
    Event::create([
      'name'=>'myName',
      'user_id'=>'1'
    ]);
    return 'Success!';
}

// 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';
    }
}

// The migration file
public function up()
{
    Schema::create('events', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->integer('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users');
        $table->timestamps();
    });
}

// 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))

I think $this->attributes['attribute_name'] is the correct way to mutate.

// Event.php
class Event extends Model
{
  protected $fillable = ['name', 'user_id'];        
  // It works as expected if I comment this out.
  public function setUserIdAttribute($value)
  {
    // Set Attribute's value.
    $this->attributes['user_id'] = Auth::id();
  }
}