Download the PHP package adelynx/laravel-api-resources without Composer

On this page you can find all versions of the php package adelynx/laravel-api-resources. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-api-resources

Laravel API Resources

Latest Version Build Status Total Downloads

Manage your resources maintaining API versioning. With a simple middleware separate routes by API version, and smart instanciate Http\Resources based on this version.

Add the middleware 'api.v:2' on your api/v2 group.

And then api_resource('App\User')->make($user) is the same as new App\Http\Resources\App\v2\User($user), but version free.

Installation

You can install this package via composer using:

The package will automatically register itself.

Config

To publish the config file to config/api.php run:

This will publish a file api.php in your config directory with the following content:

Middleware

Install this middleware on your Http/Kernel.php under the $routeMiddleware

Configure correctly

For this package to work, you need to understand how it requires resources.

If we have the following config:

This means that if you include the Api\User resource, it will instantiate App\Http\Resources\Api\v2\User.

Api works for sub organizing your structure, but you can put your Resources versioned folders in the root, like this:

Now if we include User, it will instantiate App\Http\Resources\v2\User.

Fallback

When you use a version that is NOT the latest, if you try to include a Resource that's NOT defined inside that version's directory, this will automatically fallback in the LATEST version.

This way you don't have to duplicate new resources on previous versions.

Usage

Middleware

When you group your API routes, you should now apply the middleware api.v into the group like this:

That way, if you use the Facade, you can check the current version by doing APIResource::getVersion() and will return the version specified on the middleware.

Facade

There are many ways to create resources. You can use the Facade accessor:

Global helper

Collections

Instead of make, use collection for arrays, just like Laravel's documentation.

Nested resources

To take advantage of the fallback functionality, it's recommended to use api_resource inside the resources. This way you preserve the right version, or the latest if it's not defined.

Multiple APIs

There might be the case where you have more than one API living on the same project, but using different versions. This app supports that. First, the config/api.php

Then, you need to configure the middleware. Instead of using api.v:1, you now have to specify the name: api.v:3,desktop.

Then the rest works as explained before.

Testing

Run the tests with:

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-api-resources with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1.3
illuminate/support Version 5.7.*
illuminate/http Version 5.7.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package adelynx/laravel-api-resources contains the following files

Loading the files please wait ....