PHP code example of tomschlick / laravel-linkable

1. Go to this page and download the library: Download tomschlick/laravel-linkable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tomschlick / laravel-linkable example snippets


    $model->link()

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);
    }
}

$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.