PHP code example of lukeraymonddowning / self-healing-urls

1. Go to this page and download the library: Download lukeraymonddowning/self-healing-urls 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/ */

    

lukeraymonddowning / self-healing-urls example snippets


use Lukeraymonddowning\SelfHealingUrls\Concerns\HasSelfHealingUrls;

class Post extends Model
{
    use HasSelfHealingUrls;
}

use Lukeraymonddowning\SelfHealingUrls\Concerns\HasSelfHealingUrls;

class Post extends Model
{
    use HasSelfHealingUrls;
    
    protected $slug = 'title';
}

class UnderscoreIdentifierHandler implements IdentifierHandler
{
    public function joinToSlug(string $slug, string|int $identifier): string
    {
        return "{$slug}_{$identifier}";
    }

    public function separateFromSlug(string $value): string
    {
        return Str::afterLast($value, '_');
    }
}

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(IdentifierHandler::class, UnderscoreIdentifierHandler::class);
    }
}