Download the PHP package denizgolbas/laravel-auto-relational-resources without Composer

On this page you can find all versions of the php package denizgolbas/laravel-auto-relational-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-auto-relational-resources

# Laravel Auto Relational Resources ![Laravel Auto Relational Resources](art/logo.png) **Automatic relational resource management for Laravel** [![Latest Version](https://img.shields.io/packagist/v/denizgolbas/laravel-auto-relational-resources.svg?style=flat-square)](https://packagist.org/packages/denizgolbas/laravel-auto-relational-resources) [![Total Downloads](https://img.shields.io/packagist/dt/denizgolbas/laravel-auto-relational-resources.svg?style=flat-square)](https://packagist.org/packages/denizgolbas/laravel-auto-relational-resources) [![License](https://img.shields.io/packagist/l/denizgolbas/laravel-auto-relational-resources.svg?style=flat-square)](https://packagist.org/packages/denizgolbas/laravel-auto-relational-resources)

This package automatically resolves relational data in Laravel Resource classes.

Installation

Publish the configuration file:

Usage

Using the Trait (Recommended)

Use the HasRelationalResources trait in your existing Resource classes:

Using AutoRelationalResource Class

Alternatively, you can extend your Resource class from AutoRelationalResource:

The package automatically detects loaded relations and returns them using the corresponding Resource classes.

Example Response

When you use the package with loaded relations, the response will automatically include related resources:

Controller:

Response:

As you can see, the package automatically:

Collection Response Example

When using Resource Collections, relations are automatically resolved for each item:

Controller:

Response:

Important Notes

File Structure Requirement: Collection and Resource files must follow the same path structure as your model files. The package converts the model class namespace to the Resource namespace to find the corresponding Resource class.

Examples:

If a Resource class is not found, the relation data will not be included.

Depth Control: By default, the package resolves all loaded relations with infinite depth. If you want to control the depth, you can use the max_depth configuration setting. If max_depth is null or 0, infinite depth is allowed (default). Set the max_depth value to limit the depth level.

Configuration

After publishing the configuration file, you can customize the package behavior. The configuration file is located at config/auto-relational-resources.php.

Available Configuration Options

model_namespace

Default: App\Models

The namespace where your Eloquent models are located. The package uses this to resolve Resource class names from Model class names.

Example:

resource_namespace

Default: App\Http\Resources

The namespace where your Resource classes are located. The package converts Model namespaces to Resource namespaces using this setting.

Example:

How it works:

auto_load_relations

Default: true

When set to true, relations are automatically merged into the resource response. Set to false to disable automatic relation loading.

Example:

max_depth

Default: null (infinite depth)

Controls the maximum depth level for resolving relations. Set to null or 0 for infinite depth (default). Use a positive integer to limit the depth.

Examples:

Depth levels explained:

allowed_empty_collections

Default: []

An array of collection relation names that should be included in the response even if they are empty. By default, empty collections are excluded.

Example:

This ensures that even if these collections are empty, they will appear in the response as empty arrays.

Environment Variables

You can also configure these settings using environment variables in your .env file:

Configuration Example

Here's a complete configuration example:

Features

License

MIT


All versions of laravel-auto-relational-resources with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^10.0|^11.0
illuminate/http Version ^10.0|^11.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 denizgolbas/laravel-auto-relational-resources contains the following files

Loading the files please wait ...