• Stars
    star
    25
  • Rank 954,979 (Top 19 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

URL binding for Laravel models

Laravel Linkable

StyleCI Build Status Latest Stable Version Total Downloads License

Linkable allows you to bind named routes directly to your Eloquent models. It has been tested with Laravel 5.0 and above (although it may work on older versions as well).

Making calls to route() each time you need to generate a url can be cumbersome and makes your Blade files unreadable. Instead with Linkable, you can use this syntax to generate a url:

    $model->link()

That's it! Check out the full usage below.

Install via Composer

  composer require tomschlick/laravel-linkable

Add to your model(s) and implement the interface

class User extends Model
{
    use TomSchlick\Linkable\Linkable;
    
    public function sublink(string $key, array $attr = []) : string
    {
        return route("users.$key", [
                'user_id' => $this->id, // 'user_id' is the name of the parameter in the users.* route group
                ] + $attr);
    }
}

Usage

$model->link(); // Link for the resource (example: https://your-site.com/user/7)

$model->sublink('edit'); // SubLink for the resource (example: https://your-site.com/user/7/edit)
    
$model->sublink('photos.show', ['photo_id' => 1234]); // SubLink for the resource (example: https://your-site.com/user/7/photos/1234)
    
$model->redirect(); // Generates a redirect response to the resource to use in a controller return statement.
    
$model->sublinkRedirect('edit'); // Generates a redirect response to the resource's edit page to use in a controller return statement.

More Repositories

1

request-migrations

HTTP Request Migrations for API Versioning like Stripe
PHP
185
star
2

laravel-http2-server-push

A middleware package for Laravel to enable server push for your script, style, and image assets.
PHP
167
star
3

memcached-library

A CodeIgniter Library to Interface with the Memcached cache system
PHP
130
star
4

townhouse

[WORK IN PROGRESS] A Multitenancy package for Laravel that keeps each tenant in a separate database.
PHP
112
star
5

laravel-micro-manager

Oversee jobs you have put into the queue. Track status, completion % and other job information in real time.
PHP
72
star
6

fuel-s3

FuelPHP package for the Amazon S3 PHP Class
PHP
23
star
7

fuel-postmark

A driver enabling the postmark email delivery service to be used in conjunction with Fuel
PHP
21
star
8

codeigniter-mongo-logs

Changes the default CodeIgniter Log Library to write to a MongoDB collection instead of flat log files.
PHP
20
star
9

fuel-jobqueue

A job queue & processor for Fuelphp
PHP
12
star
10

fuel-wrench

A simple maintenance package for FuelPHP allowing you to take a site online or offline.
PHP
11
star
11

codeigniter-forrst

A wrapper for the Forrst API using CodeIgniter / PHP
PHP
11
star
12

homebrew-envoy

A homebrew formula to install Laravel's Envoy
Ruby
9
star
13

mozenda-api

Mozenda API Codeigniter Library
PHP
8
star
14

fuel-mongo-crud

A MongoDB CRUD for FuelPHP
6
star
15

fuel-notifications

A notifications system for FuelPHP
PHP
6
star
16

fuel-deploy

Deploy your fuel app in a single command.
PHP
4
star
17

fuel-menu

A set of classes to create nested menus made up of ul/li elements such as the ones in twitter's bootstrap library
PHP
3
star
18

idrac-fan-control

A docker container to control iDRAC fan speeds over IPMI
PHP
3
star
19

dns-over-https

-- WORK IN PROGRESS -- DoH (DNS over HTTPS) Client for PHP / Laravel with support for many providers
PHP
2
star
20

code-style-config

Shared code style configs for my own projects.
1
star