PHPackages                             dominiquevienne/laravel-magic - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dominiquevienne/laravel-magic

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dominiquevienne/laravel-magic
=============================

Laravel helpers classes such as Controllers / Models / Requests

v3.1.1(2y ago)11.3k1[1 PRs](https://github.com/dominiquevienne/laravel_magic/pulls)MITPHPPHP ^8.1

Since May 3Pushed 2y ago2 watchersCompare

[ Source](https://github.com/dominiquevienne/laravel_magic)[ Packagist](https://packagist.org/packages/dominiquevienne/laravel-magic)[ Docs](https://github.com/dominiquevienne/laravel-magic)[ RSS](/packages/dominiquevienne-laravel-magic/feed)WikiDiscussions main Synced 4d ago

READMEChangelog (8)Dependencies (8)Versions (63)Used By (0)

Laravel Magic
=============

[](#laravel-magic)

[![GitHub last commit](https://camo.githubusercontent.com/bdf188178e90fcfc0589dc3cefd2293c2c27e0e6fa3a328d3655fbdb85010dc9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f646f6d696e697175657669656e6e652f6c61726176656c5f6d616769633f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/bdf188178e90fcfc0589dc3cefd2293c2c27e0e6fa3a328d3655fbdb85010dc9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f646f6d696e697175657669656e6e652f6c61726176656c5f6d616769633f7374796c653d666c61742d737175617265)[![Latest Version on Packagist](https://camo.githubusercontent.com/5ff92aa6614d1f6e928603a4b2d5bea145a8724627f7feedf0d5bffacf34d7f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646f6d696e697175657669656e6e652f6c61726176656c2d6d616769632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dominiquevienne/laravel-magic)[![Packagist PHP Version Support](https://camo.githubusercontent.com/4e18231be8ae98d355b2ae588c57163f2fe515219a324ec328d5b84f1cf45854/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f6d696e697175657669656e6e652f6c61726176656c2d6d616769633f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/4e18231be8ae98d355b2ae588c57163f2fe515219a324ec328d5b84f1cf45854/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f6d696e697175657669656e6e652f6c61726176656c2d6d616769633f7374796c653d666c61742d737175617265)[![GitHub top language](https://camo.githubusercontent.com/2e34fb5ddc3fdaea24dcb9ac3d6379858484af992c92f23cf4e9b6485e1cf0c9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f646f6d696e697175657669656e6e652f6c61726176656c5f6d616769633f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/2e34fb5ddc3fdaea24dcb9ac3d6379858484af992c92f23cf4e9b6485e1cf0c9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f646f6d696e697175657669656e6e652f6c61726176656c5f6d616769633f7374796c653d666c61742d737175617265)[![Packagist License](https://camo.githubusercontent.com/046dbfdc634659aedfe3c877fe7333c910c6acbfb340db58e2f1b2d6d301f716/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f646f6d696e697175657669656e6e652f6c61726176656c2d6d616769633f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/046dbfdc634659aedfe3c877fe7333c910c6acbfb340db58e2f1b2d6d301f716/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f646f6d696e697175657669656e6e652f6c61726176656c2d6d616769633f7374796c653d666c61742d737175617265)[![GitHub code size in bytes](https://camo.githubusercontent.com/d7f3f5a969edb1fbdc5370c99cac9a32c12c4252f647ad2a4dd137ed6e8d8d9b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f646f6d696e697175657669656e6e652f6c61726176656c5f6d616769633f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d7f3f5a969edb1fbdc5370c99cac9a32c12c4252f647ad2a4dd137ed6e8d8d9b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f646f6d696e697175657669656e6e652f6c61726176656c5f6d616769633f7374796c653d666c61742d737175617265)[![GitHub all releases](https://camo.githubusercontent.com/f4079b3a8cab84d9f3d9513282394c5279eef3f231884157b76ce5eb12757460/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f646f6d696e697175657669656e6e652f6c61726176656c5f6d616769632f746f74616c3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f4079b3a8cab84d9f3d9513282394c5279eef3f231884157b76ce5eb12757460/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f646f6d696e697175657669656e6e652f6c61726176656c5f6d616769632f746f74616c3f7374796c653d666c61742d737175617265)[![Packagist Stars](https://camo.githubusercontent.com/6aae49b1d4615cccdc0f5f9d69810b7b751ca078e9c737bba867bced421aeb8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f646f6d696e697175657669656e6e652f6c61726176656c2d6d616769633f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/6aae49b1d4615cccdc0f5f9d69810b7b751ca078e9c737bba867bced421aeb8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f646f6d696e697175657669656e6e652f6c61726176656c2d6d616769633f7374796c653d666c61742d737175617265)

Laravel Magic provides Abstract Controller, Model, generic Request, Traits, Exceptions and various middlewares in order to generate very easily and quickly API resources from scratch.

Support us
----------

[](#support-us)

Laravel Magic is a free open source project. If you use the project, please [star us on Github](https://github.com/dominiquevienne/laravel_magic)... it costs nothing but a click! 😉

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require dominiquevienne/laravel-magic
```

This package does not provide

- any migration
- any configuration file
- any view

### ENV variables to be set

[](#env-variables-to-be-set)

```
# Duration of the cache handled by the package
LARAVEL_MAGIC_CACHE_DEFAULT_DURATION=3600
# Used to ensure that queries handled by the AbstractController will use a Filters/ModelFilter.php class
LARAVEL_MAGIC_FILTER_MODE=paranoid
# Public key used to validate JWT tokens
OAUTH_KEY_PUB=myPublicKey
# Acceptable delay in seconds between two servers (used for tokens validation)
JWT_LEEWAY=300
```

Usage
-----

[](#usage)

### Models

[](#models)

Extending your models from `AbstractModel` will give you the opportunity to get the autocompletion that comes with PHPDoc in your IDE and will make it possible to check if a relationship exist for the given model.

It will also make it possible for `AbstractController` to make the magic happen. (see Controllers).

```
