我有一个功能,看起来像这样:查询不中Laravel功能的工作,但在其他地方工作
public function update() {
$reports = Reports::find(1);
return $reports;
}
此功能但不返回任何东西。报告表但不具有为1的p键的元素:
INSERT INTO `theDatabase`.`reports` (`pkey`, `id`, `comment`, `youtubeUrl`, `displayName`, `profilePictureUrl`, `approvalStatus`, `rep`, `created_at`, `updated_at`) VALUES (1, '1234567890', 'This is just a test report', 'https://example.com', 'Test User', 'https://example.com/somethingsomething', '0', '1', '2015-02-22 00:00:00', '2015-02-22 00:00:00')
如果此相同的函数中我,而不是做一个::all
我得到这样的回应:
[{"pkey":1,"id":"1234567890","comment":"This is just a test report","youtubeUrl":"https:\/\/youtube.com\/watch?32222","displayName":"Test User","profilePictureUrl":"https:\/\/google.com\/somethingsomething","approvalStatus":0,"rep":1,"created_at":"2015-02-22 00:00:00","updated_at":"2015-02-22 00:00:00"},{"pkey":4,"id":"12345678903","comment":"This is just a test report","youtubeUrl":"https:\/\/youtube.com\/watch?32222","displayName":"Test User","profilePictureUrl":"https:\/\/google.com\/somethingsomething","approvalStatus":1,"rep":1,"created_at":"2015-02-22 00:00:00","updated_at":"2015-02-22 00:00:00"}]
与此代码:
public function update() {
$reports = Reports::all();
return $reports;
}
所以我在这里有点困惑,为什么这不能正常工作。也;控制器中的另一个功能是使用查询,并且没有返回正确输出的麻烦。这是其他功能的代码:
public function index() {
$reports = Reports::all()->where('approvalStatus', '=', 0);
return view('reports.index', compact('reports'));
}
我想知道我在这里做的不正确吗?作为一个方面说明,这是正在通过与看起来像这样的路线POST请求称为:
Route::post('reports/update', '[email protected]');
疑问的事项,但额外的信息不受到伤害。
做一个dd($reports)
的::find(1)
返回后的输出如下:
undefined: {undefined: -909362565, " ": null}
" ": null
undefined: -909362565
编辑发表评论:
$reports = Reports::where("pkey",1);
dd($reports);
return $reports;
闻听此事:
ErrorException in Response.php line 406:
Object of class Illuminate\Database\Eloquent\Builder could not be converted to string
0: {undefined: {undefined: 2,…}, Protected property: false}
Protected property: false
undefined: {undefined: 2,…}
Protected property: " class=sf-dump-note>Application</abbr> {<a class=sf-dump-ref href=#sf-dump-748334229-ref22 title="
undefined: 2
1: 3
2: {undefined: 2,…}
3: "Protected property"
4: false
什么DD($报告)显示? – Boris 2015-02-23 04:00:51
ID字段是整数字段吗? – Boris 2015-02-23 04:02:33
@Boris将“dd”输出添加到OP。 'id'涉及增量列表中的列'pkey'。身份证本身是通过发送请求 – ComputerLocus 2015-02-23 04:05:25