我有一個功能,看起來像這樣:查詢不中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