Download the PHP package alcidesrh/laravel-generic-resource without Composer

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

A generic Laravel Resource and ResourceCollection

Basic use

This package can help you to return data as a traditional Laravel Resource without making a Resource or ResourceCollection for every single Model.


Table of Contents
  1. Requirements
  2. Installation
  3. Usage
    • GenericResource
    • GenericResourceCollection
    • GenericController
      • Route namespace and pagination configuration


Requirements

-Laravel >= 5
-php >= 7.0


Installation


Working with nested or related models

Supose the User class has a parent property of type User class as well, a belongsTo relation with itself. And also has a belongsToMany relation with Product class. So $user->parent returns an intance of User class and $user->products a collection of intances of Product class.

Let say we want a list of users with just these fields: id, name, parent (only the id and name fields of the parent) and products list (only the id, name and price fields of the product). This is how we can get only those data:


You can add many nested level as the relations allow:



Important: In order to return nested relations data it is required make the query through the model's Facade.


Note:


GenericResourceCollection


Note: Both GenericResource and GenericResourceCollection classes were made following the guide line from the official Laravel's Api Resources documentation with some extra code to make it generic. So you can expect the same structure and behavior.


GenericController

The main goal of this package is to provide GenericResource and GenericResourceCollection. However this package also provides a GenericController which can be used to fetch data that doesn't require a complex query or transformation, and it will return a GenericResource or GenericResourceCollection only with the fields that were requested or all fields if none was requested.

It can help to prevent overloading the app with routes and controller functions for every small and simple data portion required dynamically in the front-end via ajax.

The GenericController has five routes:


/generic/list get a list. It return a GenericResourceCollection


Note: It is not posible to ask for nested relations data in the fields parameter above due the generic nature of the query. DB Facade is used to make the query, which returns stdClass type.


/generic/create create an item. It will return a GenericResource


/generic/update update an item. It will return a GenericResource


/generic/item to get an item. It will return a GenericResource


/generic/delete delete an item


Route namespace and pagination configuration

Once installed runing console command php artisan vendor:publish will publish the package's configuration. It can also be done manually copy /vendor/alcidesrh/generic-resource.php to /config

/config/generic-resource.php


If you find this package useful please consider star it. Thank you.

License

This Generic Resource package for Laravel is open-sourced software licensed under the MIT license


All versions of laravel-generic-resource with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0|^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 alcidesrh/laravel-generic-resource contains the following files

Loading the files please wait ....