Comments (8)
It actually does XD
"links" => array:4 [
"first" => "http://localhost/api/foo?page=1"
"last" => "http://localhost/api/foo?page=2"
"prev" => null
"next" => "http://localhost/api/foo?page=2"
]
"meta" => array:7 [
"current_page" => 1
"from" => 1
"last_page" => 2
"path" => "http://localhost/api/foo"
"per_page" => 20
"to" => 20
"total" => 31
]
Route::group(['prefix' => 'foo'], function () {
Route::get('/', 'Users\UsersController@index');
/**
* Returns the Users resource with the roles relation.
*
* @param Request $request
* @return mixed
*/
public function index(Request $request)
{
$paginator = $this->model->with('roles.permissions')->paginate($request->get('limit', config('app.pagination_limit')));
if ($request->has('limit')) {
$paginator->appends('limit', $request->get('limit'));
}
return UserResource::collection($paginator);
}
from laravel-api.
@joselfonseca "API evolution" is the methodology i already use for my applications.
By dropping Dingo, you lose the "mime based" ressource versioning feature, but you can still use "URL based" ressource versioning. (so I am not against dropping Dingo dependency).
About replacing Fractal by Eloquent Resources : i have not yet myself tested this feature. It seems powerfull but i don't know how it handle the pagination for collection, especially the links in meta.
Do you know if it is automatically handled by Laravel or do you have to generate the url links yourself ?
(if not, it may be required to create some helpers to reproduce the Dingo collection metadata)
About the OpenAPI spec i don't know, i think it may depends on the available tools to generate api documentation. (Aglio is pretty cool for API blueprint format).
from laravel-api.
@kslimani so the pagination is handled by API resources, won't be the same but close enough (https://laravel.com/docs/5.6/eloquent-resources#pagination)
OpenAPI has nice tools to generate docs as well. This is just something came to my mind for a future release TBH i am using a lot of GraphQL and Node this days so is not something i am dying for right now, just wanted to know your opinion.
from laravel-api.
I have read the pagination part for API resources, i was just wondering how the urls in "links" and "meta" are generated in the provided example :
// Copy paste from https://laravel.com/docs/5.6/eloquent-resources#pagination
use App\User;
use App\Http\Resources\UserCollection;
Route::get('/users', function () {
return new UserCollection(User::paginate());
});
I guess i will have to performs some tests.
from laravel-api.
Yea, I was looking into that and got this:
[
"data" => array:0 []
"links" => array:4 [
"first" => "http://localhost/api/users?page=1"
"last" => "http://localhost/api/users?page=2"
"prev" => null
"next" => "http://localhost/api/users?page=2"
]
"meta" => array:7 [
"current_page" => 1
"from" => 1
"last_page" => 2
"path" => "http://localhost/api/users"
"per_page" => 20
"to" => 20
"total" => 31
]
Using
/**
* Returns the Users resource with the roles relation.
*
* @param Request $request
* @return mixed
*/
public function index(Request $request)
{
$paginator = $this->model->with('roles.permissions')->paginate($request->get('limit', config('app.pagination_limit')));
if ($request->has('limit')) {
$paginator->appends('limit', $request->get('limit'));
}
return UserResource::collection($paginator);
}
data is empty because I removed it, but the user data is there. I am only worried about like the includes, have not seen how that works.
from laravel-api.
What happen if instead of /users
you rename to something else ?
Route::get('/foobar', function () {
return new UserCollection(User::paginate());
});
Does it properly generate links like http://localhost/api/foobar?page=1
?
from laravel-api.
That's pretty cool !
from laravel-api.
Lets leave this for later XD.
from laravel-api.
Related Issues (20)
- Route [password.reset] not defined. HOT 1
- Add docker-compose configuration for development HOT 1
- Upgrade to Laravel 7 HOT 4
- postman return error on create new User HOT 3
- Assets file update/remove HOT 1
- Update Scaffold to Laravel 8 HOT 3
- laravel 7 User does not have the right permissions. HOT 4
- Add Registration Endpoint
- Add Forgot Password Endpoint to request the email.
- Add Reset password endpoint to save the new password from the email
- Add socialite integration for social login as a grant type on passport
- Refactor to use Form requests as validators HOT 1
- how to reset password without login (Forget Password)? HOT 1
- ParseError: syntax error when running through localhost xampp HOT 2
- Invalid client id
- Invalid grant response HOT 1
- Is this any option with pagination and filter while taking list user HOT 2
- File upload not working HOT 1
- internal api/asset with file upload not working HOT 3
- Error when running composer api-docs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-api.