Download the PHP package sebastiaanluca/laravel-route-model-autobinding without Composer

On this page you can find all versions of the php package sebastiaanluca/laravel-route-model-autobinding. 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-route-model-autobinding

Automatically bind Eloquent models as route segment variables

Latest stable release Build status Total downloads Total stars

Read my blog View my other packages and projects Follow @sebastiaanluca on Twitter Share this package on Twitter

Immediately start using models in your routes without having to worry about maintaining any list or map.

Medium to large Laravel applications can have a lot of models. If you're a heavy user of route model binding to automatically retrieve and inject model instances in your controllers, that means you have to manually register dozens or hundreds of models in your route service provider. You then need to do the same for each new, changed, or deleted model which makes this nifty feature hard to maintain and easy to forget.

This package solves the issue of manually having to register each model by doing all the grunt work for you. It reads your composer.json PSR-4 autoload section and scans all their model directories for usable Eloquent models. It then explicitly binds each model into the router as a route segment variable using a case type of your choosing (see configuring casing).

Example

Get rid of this boilerplate code:

And just do this (for any Eloquent model in your application):

Table of contents

Requirements

How to install

Via Composer:

How to use

Defining model namespaces

Laravel route model autobinding uses your composer.json PSR-4 autoload section to know which namespaces and paths to scan. In any new Laravel project, the default App\\ namespace is already in place, so for most projects no additional setup required. If you have other namespaces registered like local modules or (dev) packages, those will be scanned too.

Furthermore it filters out traits, abstract classes, helper files, and other unusable items to only bind valid Eloquent models.

Route segment variables

After installing the package, you can immediately get to work using the aliased Eloquent models in your routes:

Besides scanning and aliasing your models for you, this package alters no native Laravel functionality. Therefore, see the Laravel documentation on how to use route model injection.

Caching bindings in production

To cache all bindings and speed up your application in production, add the cache command to your deploy scripts:

This scans all your current models and writes a static cache file to the bootstrap/cache directory. Upon subsequent framework booting, it reads the cache file instead of scanning and aliasing on-the-fly.

Note that this thus disables runtime scanning, meaning new models will not be recognized and changes to existing models will not be reflected (not very handy during development). You can however still change the case type in the configuration file, as the binding happens in a later stage.

To clear the cache file, run:

Configuration

Run

and select

to publish the configuration file.

Casing

By default, the case type for aliasing models is set to camel case. You can change this to use camel, snake, or studly casing.

See \SebastiaanLuca\RouteModelAutobinding\CaseTypes for possible options.

Camel case (default):

Snake case:

Studly case:

The case type can still be changed after caching your models.

License

This package operates under the MIT License (MIT). Please see LICENSE for more information.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

Contributing

Please see CODE OF CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

About

My name is Sebastiaan and I'm a freelance back-end developer specializing in building custom Laravel applications. Check out my portfolio for more information, my blog for the latest tips and tricks, and my other packages to kick-start your next project.

Have a project that could use some guidance? Send me an e-mail at [email protected]!


All versions of laravel-route-model-autobinding with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3
laravel/framework 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 sebastiaanluca/laravel-route-model-autobinding contains the following files

Loading the files please wait ....