我有這一套雄辯模式:如何使用Laravel 5.2在eloquent create方法中自動包含來自Request() - > ip()的客戶端IP地址?
class UserModel extends Model
{
protected $fillable = array(
'first_name',
'last_name',
'email',
'password',
'ip',
);
protected $table = 'users';
}
的想法是......我想,只要他/她註冊成爲用戶在我們網站上,包括客戶端的IP地址。
在Laravel 5.2,我們可以使用要求()類
請求獲取客戶端的IP地址() - > IP()
https://laravel.com/api/5.2/Illuminate/Http/Request.html#method_ip
創建用戶時使用雄辯模型進行記錄,我使用create()方法,因此我不必爲每個字段的值分配「IP」字段的值。
是否有任何方法來自UserModel自動分配的'IP'字段值來自Request() - > ip()方法?
public function createNewUser(Request $request) {
return $this->user->create($request->all());
}
任何建議/意見將不勝感激。
謝謝!
我很高興能幫上忙。 ) –