Download the PHP package oddvalue/link-builder without Composer
On this page you can find all versions of the php package oddvalue/link-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oddvalue/link-builder
More information about oddvalue/link-builder
Files in oddvalue/link-builder
Package link-builder
Short Description Consistent interface for generating URLs and links for models
License MIT
Homepage https://github.com/oddvalue/link-builder
Informations about the package link-builder
Link Builder
A consistent interface for generating URLs and links for php models.
- Installation
- Usage
- Creating a Generator
- Preparing Your Model
- Generating Links
- Link Attributes
Installation
Via Composer
Usage
Creating a Generator
First off you will need a generator class for your model. This generator class will be responsible for deciding what the href and label of the link for your model should be.
This is the minimum generator setup:
You don't have to extend \Oddvalue\LinkBuilder\Contracts\LinkGenerator
.
Preparing Your Model
Next, in your model, implement \Oddvalue\LinkBuilder\Contracts\Linkable
.
There is also a trait for ease of use but it is not essential to use it:
\Oddvalue\LinkBuilder\Traits\LinkableTrait
For example:
Generating Links
Once you have set all your linkable models up with their respective link generators you will have a consistent interface for handling their URLs and links in your app.
e.g.
There is also a helper method for fetching the link generator of a model:
Link Attributes
In order to set classes and other attributes on the generated links you may either pass them in via the options array on the getLinkGenerator(array)
method or you can call the setAttributes(array)
method on the generator itself.