Download the PHP package singlequote/laravel-api-resource without Composer

On this page you can find all versions of the php package singlequote/laravel-api-resource. 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-resource

Laravel API Resources made simple

This package helps developers efficiently manage resource transformations, handle relationships, and customize resource attributes, ensuring a clean and maintainable API development workflow. Whether you're building a new API or maintaining an existing one, laravel-api-resource enhances your ability to deliver robust and compliant JSON responses with minimal effort.

This package generates a complete api set for your model. From controller to action to request to resource. All you have to do is edit the form requests.

Version > 2.1 adds the ability to pass additional attributes to the relation and has method. See the with method.

Latest Version on Packagist Total Downloads

Installation

Publish files

Publish the config

Publish stub files

API Resource Generation

With the command above, you can generate a complete set for your API resources including the API controller, actions, requests, and an API resource.

For example, if we would want to generate an API resource for our User model.

The following files will be created:

After the generation is completed you can add your api resource route to your api.php route file.

Resource methods

The package comes with default methods that can be used to quickly setup your api. For instance the policy service can be used to add policies to your resource response.

In addition you can pass additional policy methods as a second parameter.

Api methods

The package comes with default api options. To use the provided helpers, add the HasApi trait to your models. In the code previews below we use a package named Ziggy to parse the url. If you don't use any javascript libraries to build your url you have to manual build the url according to the previews below. For example:

will look like

Manual

helper value
limit number
search array
where array
orWhere array
whereIn array
whereNotIn array
whereNull string
whereNotNull string
has array
doesntHave array
whereRelation array
with array
select array
orderBy string
orderByDesc string

limit

The default limit provided by the package is set to 1000 results per page. You can change the default in the laravel-api-resource config file. To change the limit for a single request you can use the limit helper.

search

A search helper is available if you want to create a search input. The search field accepts an array with 2 required fields. The field and query. The fields are the columns the api should search in. The query is the query used to search in the columns.

If you want to search all fillable columns within your model you can use the wildcard * as your searchfield

where

You may use the query builder's where method to add "where" clauses to the query. The most basic call to the where method requires 2 arguments. The first argument is the name of the column. The second argument is the value to compare against the column's value.

You may also pass an additional operator to retrieve data for example, get all users younger than a certain date

Digging Deeper

If you want to filter multiple times on the same column, you can change the where object to an array and add the where statements as array objects.

Below we will retrieve all users that were created on a specific day

Available operators Operator Shorthand
startsWith sw
endsWith ew
notContains nin
contains in
equals eq
notEqual neq
greater gt
greaterEquals gte
lesser lt
lesserEquals lte

whereIn

The whereIn method verifies that a given column's value is contained within the given array:

whereNotIn

The whereNotIn method verifies that the given column's value is not contained in the given array

whereNull

The whereNull method verifies that the given column's value is NULL

whereNotNull

The whereNotNull method verifies that the given column's value is not NULL

has

When retrieving model records, you may wish to limit your results based on the existence of a relationship. For example, imagine you want to retrieve all users that have at least one role.

Digging deeper

You can add additional parameters to the has object. For example, if you would like to get all users that with certain roles.

doesntHave

When retrieving model records, you may wish to limit your results based on the existence of a relationship. For example, imagine you want to retrieve all users don't have any roles attached.

whereRelation

If you would like to query for a relationship's existence with a single, simple where condition attached to the relationship query.

You may also pass an additional operator to retrieve data for example, get all users where the role was created after a certain date.

with

Sometimes you may need to eager load several different relationships. To do so, just pass an array of relationships to the with method

Using with on sub relations When you want to retrieve a relation containing other relations you can set a property on each model. This allows you to allow certain models to accept multiple depths Add the property $apiRelations to your model.

Passing additional properties to relations The with method also accepts a json object. This way you can pass the same methods to relations. For example, if you would like to retrieve only the name of the roles

Even include the permissions

select

Sometimes you may only need a few columns from the resource and keep your api responses small.

orderBy/orderByDesc

Sometimes you may want to change the ordering form your api response. You can use the orderBy or orderByDesc helper

Order relations

Custom orderable columns

When using for example the withCount or withSum on your model query by default that column isn't sortable because it doesn't exists in your fillable attribute. To make the custom column sortable you can add the $apiOrderBy attribute to your model to make those columns sortable

To make for example article prices sortable, add the withSum to your query.

next add the orderBy to your api request

Contributing

Please see CONTRIBUTING for details.

Postcardware

You're free to use this package, but if it makes it to your production environment, we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Quotec, Traktieweg 8c 8304 BA, Emmeloord, Netherlands.

Credits

License

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


All versions of laravel-api-resource with dependencies

PHP Build Version
Package Version
Requires reedware/laravel-relation-joins Version ^8.0
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 singlequote/laravel-api-resource contains the following files

Loading the files please wait ....