Download the PHP package silvertipsoftware/rest-router without Composer
On this page you can find all versions of the php package silvertipsoftware/rest-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download silvertipsoftware/rest-router
More information about silvertipsoftware/rest-router
Files in silvertipsoftware/rest-router
Package rest-router
Short Description Smart url construction using classes and models
License MIT
Homepage https://github.com/SilvertipSoftware/RestRouter
Informations about the package rest-router
RestRouter
About
The rest-router
package allows you to construct urls by passing in an Eloquent
model or corresponding class name.
Features
- Smart url construction using classes and models.
Installation
Require the silvertipsoftware/rest-router
package in your composer.json
and update your
dependencies:
The package can be used by directly calling url()
or path()
on
SilvertipSoftware\RestRouter\RestRouter
, but for convenience, a mixin for Laravel's built-in
URL
facade is provided. To use, in your RouteServiceProvider::boot
method, call:
The url()
and path()
methods will now be available on URL
.
Usage
RestRouter
is built primarily to work on routes defined with the Route::resource()
method of
Laravel's router, although hand-rolled routes can also be used. Behind the scenes, RestRouter
uses the route names to create urls; the actual text of the url is irrelevant.
Simple Resource Routes
Assume that the following resource has been defined:
Then in your code you can do:
Fallbacks
Not every REST action need be defined on a resource. RestRouter
will check other route names
which generate the same url, since it is not concerned with the HTTP method used. For example:
Prefixed Resource Routes
RestRouter
needs to be given any route name prefixes (not uri prefixes) defined. For example:
Non-REST Actions
If you've defined non-typical REST actions on your resource, you can pass an action
option to
RestRouter
to find that route name. For example:
Nested Resources
RestRouter
assumes shallow resources by default. If you use nested resources, this can be enabled
globally or on a per-route basis.
For enabling nested resource support globally, in your RouteServiceProvider
insert:
On a per-route basis, pass a "shallow" => false
option to your call to url()
or path()
as
below. For example:
Route Generation Options
If the last argument is an array, it is treated as a keyed array of options to modify the url. Available options are:
Any other keys added to the $options
parameter are treated as either query parameters for the
generated url, or as route parameters if they are defined.
Also works in blade templates:
will render to:
License
Released under the MIT License, see LICENSE.