如何在Laravel中保存数据

时间:2019-09-21 14:01:37

标签: laravel

在HomeController.php中,我有

# Get the default notebook for the current user
notebook = note_store.getDefaultNotebook()
# Allow it to be publicy viewable
notebook.published = True

notebook.publishing = Types.Publishing()
# Define the URI for the shared notebook
notebook.publishing.uri = "iseeyou"
# Give it a description
notebook.publishing.publicDescription = "My default notebook is public!"
# Update it on the server
note_store.updateNotebook(notebook)
# Build the URL for visiting the notebook on the web
notebookUrl = "https://%s/pub/%s/%s/" % \
                (client.service_host, 
                 user_store.getUser().username, 
                 notebook.publishing.uri)

print "View this notebook:",
print notebookUrl

# Output:
# https://sandbox.evernote.com/pub/inkedmn/iseeyou/

然后,我想将此IP接收到我的数据库中。但是下面的行不起作用。错误说    在字符串上调用成员函数save()

      $ip = Request::ip();

如何存储这些数据?

2 个答案:

答案 0 :(得分:3)

$ip不是字符串对象,您需要创建IP模型并使用$ip创建新实例,然后才能将其保存到数据库。

答案 1 :(得分:0)

类似的东西:

$ip = new Ip(['ip' => Request::ip()]);
$ip->save()

Ip::create(['ip' => Request::ip()]);

应该工作!