Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
d8vjork committed Oct 30, 2023
1 parent 584f111 commit fbea2ec
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,63 @@ Add permalinks to your application's Eloquent models
composer require open-southeners/laravel-model-permalink
```

### Usage

First run the command to publish the config and **required migrations** files:

```bash
php artisan vendor:publish --provider="OpenSoutheners\\LaravelModelPermalink\\ServiceProvider"
```

Then run new migrations:

```bash
php artisan migrate
```

And add the `PermalinkAccess` interface, `HasPermalinks` trait and `getPermalink` method to the models you want to have permalinks:

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use OpenSoutheners\LaravelModelPermalink\HasPermalinks;
use OpenSoutheners\LaravelModelPermalink\PermalinkAccess;

class Post extends Model implements PermalinkAccess
{
use HasPermalinks;

/**
* Get permanent link for this model instance.
*/
public function getPermalink(): string
{
// Here is where you return the route that all posts permalinks should use...
return route('posts.show', $this);
}
}
```

Now to generate permalinks to this `Post` or any configured model you can call the following anywhere in your application's code:

```php
<?php

use App\Models\Post;
use OpenSoutheners\LaravelModelPermalink\GeneratePermalink;

$post = Post::find(1);

GeneratePermalink::for($post);

// or getting directly the route from returned ModelPermalink object

GeneratePermalink::for($post)->getModelPermalink();
```

## Partners

[![skore logo](https://github.com/open-southeners/partners/raw/main/logos/skore_logo.png)](https://getskore.com)
Expand Down

0 comments on commit fbea2ec

Please sign in to comment.