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');
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
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. :)