I have a function that looks like this:
public function update() {
$reports = Reports::find(1);
return $reports;
}
This function however is not returning anything. The reports table however does has an element with a pkey of 1:
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')
And if within this same function I instead do a ::all
I get this response:
[{"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"}]
That is with this code:
public function update() {
$reports = Reports::all();
return $reports;
}
So I am a little confused here why this is not working correctly. Also; another function within the controller is using a query and it has no troubles returning the correct output. This is the code of the other function:
public function index() {
$reports = Reports::all()->where('approvalStatus', '=', 0);
return view('reports.index', compact('reports'));
}
I am wondering what I am doing incorrectly here? As a side note, this is being called via a post request with a route that looks like this:
Route::post('reports/update', 'ReportsController@update');
Doubt that matters, but extra information doesn't hurt.
Doing a dd($reports)
after the ::find(1)
returns the following output:
undefined: {undefined: -909362565, " ": null}
" ": null
undefined: -909362565
Edit for comment:
$reports = Reports::where("pkey",1);
dd($reports);
return $reports;
Getting this:
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