Download the PHP package mustafafares/laravel-selective-response without Composer

On this page you can find all versions of the php package mustafafares/laravel-selective-response. 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-selective-response

Laravel Selective Response

Automatic API resource filtering based on model select() queries with optional Scramble documentation support.

Features

Installation

Publish the configuration file:

Quick Start

1. Update Your Resources

Change your resources to extend BaseApiResource instead of JsonResource:

2. Use in Controllers

That's it! The filtering happens automatically.

Usage Examples

Basic Usage

Always Include Fields

Disable Filtering

With Relationships

Dynamic Always-Include

Scramble Extension

The package includes an optional extension for Scramble that automatically detects select() calls in your controllers and updates the API documentation to show only selected fields.

Setup

  1. Install Scramble (if not already installed):

  2. Install PHP Parser (required for the extension):

  3. Publish Scramble config (if not already done):

  4. Register the extension in config/scramble.php:

How It Works

The extension uses PHP Parser to analyze your controller methods and find select() calls. It then filters the OpenAPI schema to show only the selected fields in the documentation.

Before Extension:

After Extension:

Disable Scramble Extension

You can disable the Scramble extension in the config:

Configuration

Publish the configuration file:

Available Options

Common Patterns

List Endpoint (Efficient)

Detail Endpoint (Full Data)

Search with Dynamic Fields

Force Full Response

Advanced Features

Custom Always-Include Logic

Conditional Computed Fields

Testing

Troubleshooting

Issue: All fields still returned

Solution: Verify you're extending BaseApiResource, not JsonResource

Issue: Relationships not working

Solution: Use $this->whenLoaded() for relationships

Issue: Computed fields missing

Solution: Use $this->whenAttributeLoaded() for computed fields

Issue: Need specific field always

Solution: Add to protected $alwaysInclude = ['field']; in your resource

Issue: Scramble extension not working

Solutions:

  1. Clear config cache: php artisan config:clear
  2. Verify extension is in config/scramble.php
  3. Check PHP Parser is installed: composer show nikic/php-parser
  4. Ensure Scramble is installed: composer show dedoc/scramble

Performance Benefits

Endpoint Without Select With Select Improvement
User list 50 KB 10 KB 80% smaller
Search 100 KB 20 KB 80% smaller
Summary 2 KB 0.5 KB 75% smaller

Result: Faster APIs, lower bandwidth costs, better UX!

Migration Guide

From JsonResource to BaseApiResource

  1. Change the parent class:

  2. Add the import:

  3. That's it! Your toArray() method works exactly the same.

Requirements

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.


All versions of laravel-selective-response with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.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 mustafafares/laravel-selective-response contains the following files

Loading the files please wait ...