Download the PHP package svanthuijl/laravel-routable-models without Composer

On this page you can find all versions of the php package svanthuijl/laravel-routable-models. 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-routable-models

Associate routes with Eloquent models

This packages allows you to create eloquent models which have their own routes. The routes will automatically be generated when the model is saved and the routes will automatically be registered in the router.

Localized routes

The package also offers support for localized routes for translatable models. This is built on top of "spatie/laravel-translatable".

Installation

This package can be installed through Composer.

Migrations

Migrations are automatically loaded. Optionally, you can publish the migrations of this package with this command:

Config

Optionally, you can publish the config file of this package with this command:

The config file was built to be configured with dotenv variables.

Service provider

The service provider for this package is not discovered automatically. Register the RoutableServiceProvider manually in your config/app.php service providers section.

Important! Make sure that this is the last service provider to be registered since it does check for previously registered routes.

Using the package

Implement the package

To make a model routable implement the interface and use the trait in your model.

Configure the routes

Configuration of the routes is done by adding a method to your model. In this method you call to create a route. The first property is the name of the route, the second is the used route generator. By default the name is and the used route generator is

This example will create two routes (get and post on the same path) for every model that will be created.

Retrieve the routes

The default route is accessible with route accessor.

Handle the routes

The package will automatically register/capture the created routes and will call the configured action. The model will be passed to the action as .

Localization

The package supports two types of localized routes.

  1. Multiple localized routes for translated modes using
  2. Single route prepended with locale for models with a property

All localized routed will have the locale prepended to the route path.

Enabling localization for the package

Localized routes are enabled by configuring the and in the dotenv file.

Implementing localization for a translatable model

For this feature first of all make sure that you have implemented for yur model. Then add to the route configuration.

Using localized translatable routes

Now for this model multiple routes will be created.

Handling localized routes

The package will automatically set the locale for the request when a localized route was accessed.

Implementing localization for not translated model

A model can be sat as being localized by calling on the route generator. The route generator now expects a property on the model to contain the locale. The property name can be overwritten by adding parameters to the call.

Usage:

Also in this case when accessing one of these routes the app()->locale() will be automatically be set to the proper locale.

Disabling routes

Route generation for a specific model can be disable by overwriting the method to return .

The route generator

Routes can be manipulated with the options shown in the example below. You can also replace the default route generator with your own for more advanced implementations. Make sure your custom route generator class implements the

Testing

Run the tests with:


All versions of laravel-routable-models with dependencies

PHP Build Version
Package Version
Requires php Version ^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 svanthuijl/laravel-routable-models contains the following files

Loading the files please wait ....