Laravel 4 - 通过hasMany关系插入

Here is my model relationship...

class User extends Eloquent {
    public function loginLog(){
        return $this->hasMany('LoginLog');
    }
}

class LoginLog extends Eloquent {
    public function user(){
        return $this->belongsTo('User');
    }
}

When I insert data into the login_logs table in my database all the data is input correctly but it does not insert the id of the user into user_id (laravel expects this).

Here is how I am inserting into login_logs.

$user->loginLog()->insert(array(
    'user_id'       => $user->id, //I could put it here, but then what is the point in a relationship?
    'email'         => $user->email,
    'ip_address'    => Request::getClientIp(),
    'country_code'  => $country_code,
    'status'        => $status,
    'created_at'    => Helper::dateTimeNow()
));

You have to attach the user.

Its here in the docs http://laravel.com/docs/eloquent#inserting-related-models

Update:

On rereading your question I think you want to find the user by their id first as you are doing $user->loginLog()->insert not $loginLog->insert

Try chaining it so: $user::find($theIDYouWant)->loginLog()->insert