Laravel-mongodb: Where not working using API in Laravel.

Created on 8 Sep 2017  路  6Comments  路  Source: jenssegers/laravel-mongodb

I'm making an API REST in Laravel, when I use the controller, it's not returning data, but when I use Laravel Tinker, it works fine and returns data.

In the controller

public function show(Ups $trademark){
return Ups::where('trademark','=', $trademark)->get();
}

In Laravel Tinker
Ups::where('trademark','=', 'Schneider')->get();

App\Ups {781
_id: MongoDB\BSON\ObjectID {763
+"oid": "59aea41e0bc6b8581e35e572",
},... . .. .

But when I call the method show from the api, returns nothing.

api/upss/Schneider

(2/2) NotFoundHttpException
No query results for model [App\Ups].

I tried the same thing with the Index method, and it works perfectly, it returns the whole collection in Json.

My api.php in Laravel

Route::get('upss', '\App\Http\Controllers\Api\UpsApiController@index'); Route::get('upss/{trademark}', '\App\Http\Controllers\Api\UpsApiController@show');

Most helpful comment

I got it working, by type casting the values in where clause. All my collection keys were stored as strings.

For example:

you can try Model::where('id', '=', (string) $id)->get();

I believe tinker has a different backend engine then normal engines which work with different OS.

so there was no issue with the library from start. I hope it helps. :)

All 6 comments

I am having the same issue with Laravel 4, it works with tinker but not on the actual api, it returns NULL.
were you able to find it working?

Not yet.
I wrapped the value into simple apostrophe 'value' , but it doesn't work.

If I find a solution I'll post it here.

If somebody gets the answer, post it here

I got it working, by type casting the values in where clause. All my collection keys were stored as strings.

For example:

you can try Model::where('id', '=', (string) $id)->get();

I believe tinker has a different backend engine then normal engines which work with different OS.

so there was no issue with the library from start. I hope it helps. :)

Thank you so much @tariqbilal !!! Have a good day..

mantap bosku @tariqbilal

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomartailored picture tomartailored  路  3Comments

imrannazirbhat picture imrannazirbhat  路  3Comments

yupangestu picture yupangestu  路  3Comments

pirmax picture pirmax  路  3Comments

bastiendonjon picture bastiendonjon  路  3Comments