Download the PHP package jcfrane/laravel-resource-scope without Composer

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

Laravel Resource Scope

Tests Latest Stable Version License

Control which fields your Laravel API Resources return based on context. Define scopes like listing, detail, or summary and let the frontend request only the data it needs.

Inspired by Symfony's serialization groups.

Requirements

Installation

The package auto-discovers its service provider. No manual registration needed.

Publish Config (Optional)

Quick Start

1. Add the trait to your resource

2. Register the middleware

In bootstrap/app.php:

Or apply it to specific route groups:

3. Request scoped data

You can also pass the scope via header:

Defining Scopes

Method-based (recommended)

Define a scopeDefinitions() method that returns scope name => allowed field keys:

Attribute-based

Use PHP 8 attributes on the resource class:

If both are present, scopeDefinitions() takes priority.

Scope Cascading

When a resource contains nested resources, you can control how scopes propagate. There are two ways to define mappings:

Method-based mappings

Attribute-based mappings

You can also define mappings directly in the #[ResourceScope] attribute using the mappings parameter:

When the listing scope is active on PostResource, the nested UserResource will automatically use the summary scope.

If both scopeMappings() method and attribute mappings are present, the method takes priority. If no mapping is defined, the parent's scope name passes through to nested resources. If the nested resource doesn't define that scope, it returns all fields.

Works with Laravel's Conditional Fields

Scoping works alongside whenLoaded(), whenHas(), and when(). Both conditions apply — Laravel's conditional checks run first, then scoping filters the keys:

Backwards Compatible

No breaking changes to existing API responses.

Configuration

Published config file (config/resource-scope.php):

Testing

License

MIT


All versions of laravel-resource-scope with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.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 jcfrane/laravel-resource-scope contains the following files

Loading the files please wait ...