php - Laravel 尝试保存到数据库时出错
问题描述
我对 laravel 有点陌生,我大约 3 个月前就开始了。我正在尝试将您从 twitteroath + 关注者返回的数据保存到我的数据库中,但是当我尝试保存时出现错误。Atm 我正在使用 laravel 5.6 和 php 7.6
这是我的控制器中商店功能中的代码。我的控制器中的所有内容都可以保存到每个日期,即使 $twitter = new twitter 也可以正常工作。如果我最后转储()/dd()$twitter,它必须更正信息。但是一旦我添加了 $twitter->save(); 它返回一个错误
define('CONSUMER_KEY', getenv('TWITTER_CONSUMER_KEY'));
define('CONSUMER_SECRET', getenv('TWITTER_CONSUMER_SECRET'));
define('OAUTH_CALLBACK', getenv('TWITTER_OAUTH_CALLBACK'));
$request_token = [];
$request_token['oauth_token'] = $_SESSION['oauth_token'];
$request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret'];
if (isset($_REQUEST['oauth_token']) && $request_token['oauth_token'] !== $_REQUEST['oauth_token']) {
return redirect::to('dashboard.settings.index')->with('message', 'Login Failed!');
}
//This is for getting the twitteroath access_tokens, id and screenname.
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
$access_token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $_REQUEST['oauth_verifier']]);
$_SESSION['access_token'] = $access_token;
//This is used to get the the follower count
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
$user = $connection->get('account/verify_credentials', ['tweet_mode' => 'extended', 'include_entities' => 'true']);
$twitter = new twitter;
$twitter->twitter_id = $access_token['user_id'];
$twitter->auth_token = $access_token['oauth_token'];
$twitter->auth_token_secret = $access_token['oauth_token_secret'];
$twitter->username = $access_token['screen_name'];
$twitter->followers = $user->followers_count;
$twitter->save(); //<--- this is where is gets the error
return redirect('/dashboard/settings');
这是我连接到我的数据库的模型
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class twitter extends Model
{
public function twitter_post()
{
return $this->hasMany('App\Models\twitter_post');
}
public function ContactInformation()
{
return $this->hasOne('App\Models\ContactInformation');
}
}
万一有人想要它,这也是我数据库中的表。
我想知道我做错了什么是我正在寻找的一个非常小的错误。
编辑
我忘记在这里发布错误了。
SQLSTATE [42S22]:找不到列:1054 '字段列表'中的未知列'updated_at'(SQL:插入
twitters
(twitter_id
,,,,,,,,) 值(123,测试,测试auth_token
,auth_token_secret
测试username
,followers
123,2018-11-01 2018-11-01 10:50:18 10:50:18))updated_at
created_at
这是我回来的错误。
解决方案
在您的模型中编写以下代码
public $timestamps = false;
然后再试一次
推荐阅读
- c# - 组合相同但接受不同变量的方法
- coq - coq 中存在变量的实例化规则
- docker - 将 docker 容器部署到 heroku 会产生:与 privilidges 相关的 nginx 错误
- apache-spark - 如何在 spark 的 csv 文件中加载“dd/MM/yyyy”格式的日期?
- javascript - 在 AJAX 成功上解析 BBCode
- javascript - 使用“innerHTML”时出现奇怪的错误..?
- javascript - 将 jquery 对象返回到普通字符串
- jquery - Kendo Treeview 处理空 HierarchicalDataSource
- linux - 如何用 tr 或 sed 用字符串替换另一个文件中的“Ñ”?
- python - Python中类的循环引用