Php Artisan tinker 不会在 table 中保存更新的条目
Php Artisan tinker wont save updated entry in table
PHPLARAVEL 5。所以我想要作业 table 中状态为零的最新项目。现在我只想尝试更新作业类型。但它会拉出我想要更新的正确项目,如下所示。我尝试更新和保存并得到这个错误。
>>> $job=\App\Job::orderBy('created_at', 'desc')->where('status', 0)->where('created_at', '>', '$current_dt')->first()
=> <App\Job #000000006ea292f40000000026d13dc7> {
job_id: "4",
job_hash: "ujshdujsh",
job_type: "ujshdujsh",
parameters: "",
created_at: "2015-03-16 17:41:07",
updated_at: "2015-03-16 17:41:07",
available_ts: "0000-00-00 00:00:00",
status: "0"
}
>>> $job->job_type='updated'
=> "updated"
>>> $job->save();
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause'
(SQL: update `jobs` set `job_type` = updated, `updated_at` = 2015-03-16 17:58:38 where `id` is null)'
>>>
http://laravel.com/docs/5.0/eloquent#basic-usage
protected $primaryKey = 'job_id';
PHPLARAVEL 5。所以我想要作业 table 中状态为零的最新项目。现在我只想尝试更新作业类型。但它会拉出我想要更新的正确项目,如下所示。我尝试更新和保存并得到这个错误。
>>> $job=\App\Job::orderBy('created_at', 'desc')->where('status', 0)->where('created_at', '>', '$current_dt')->first()
=> <App\Job #000000006ea292f40000000026d13dc7> {
job_id: "4",
job_hash: "ujshdujsh",
job_type: "ujshdujsh",
parameters: "",
created_at: "2015-03-16 17:41:07",
updated_at: "2015-03-16 17:41:07",
available_ts: "0000-00-00 00:00:00",
status: "0"
}
>>> $job->job_type='updated'
=> "updated"
>>> $job->save();
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause'
(SQL: update `jobs` set `job_type` = updated, `updated_at` = 2015-03-16 17:58:38 where `id` is null)'
>>>
http://laravel.com/docs/5.0/eloquent#basic-usage
protected $primaryKey = 'job_id';