Download the PHP package kayrunm/polybind without Composer

On this page you can find all versions of the php package kayrunm/polybind. 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 polybind

Polybind

Polymorphic route-model binding for Laravel.

Pre-requisites

This package requires the following:

Installation

To install the package, you simply need to run the following command:

The service provider for the package will automatically be registered, but if you wish, you can optionally add the following in your config/app.php file:

Finally, you just need to alias the middleware in your $middlewareAliases in app/Http/Kernel.php:

You can skip aliasing the middleware if you have no intention of using per-route parameters, as it just makes it easier to add the middleware parameters. If you do skip this step, you'll have to apply the middleware using the full Polybind classname.

Configuration

This package allows for you to configure the default route parameters and the resolution logic. To start with this, you need to publish the configuration file:

You can now edit the config/polybind.php file with your chosen defaults.

Usage

Polybind works via a middleware that you add to your polymorphic routes. The simplest way to get started is to add the middleware to your route definition, like so:

Polybind will then do its magic when you access this route, by automatically resolving the model and allowing you to access the model in your controller method via the $model parameter:

Note: Polybind requires that your models are registered in Relation::morphMap().

Type validation

Polybind allows you to hint the types of model that a route accepts, either with union/intersection types or even with interfaces. If Polybind resolves a model that doesn't match the type that you have type hinted, it will throw a Kayrum\Polybind\Exceptions\InvalidModelType exception. If you don't use any type hinting in your controller method, Polybind will allow any Model to be resolved.

Here's an example of type hinting with an interface:

And here's an example of type hinting using a union type:

Per-route configuration

Polybind also allows you to configure the route parameters for the model type and model identifier, as well as the name you use for the parameter in your controller method, on a per-route basis. Here's an example of how to do that:

Adding to your entire application

If you make use of polymorphic route-model binding throughout your application, you may find it easier to simply apply Polybind's functionality on all of your routes. Polybind will only run on routes where it finds a matching type and identifier parameter.

To do this, simply add the Polybind middleware to the middleware groups you would like it to run on, for example in the web and api groups in app/Http/Kernel.php:

Note: Make sure that the Polybind middleware is applied after the SubstituteBindings middleware.


All versions of polybind with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version ^10.22
illuminate/http Version ^10.22
illuminate/routing Version ^10.22
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 kayrunm/polybind contains the following files

Loading the files please wait ...