WORK IN PROGRESS, some functionalities may be changed in the future.
Add internal link to your published assets.
You can install the package via composer:
composer require kaqazstudio/laravel-interlink
If autodiscovery doesn't work, register the package in your project manually.
■ Add this line to config/app.php > providers array
KaqazStudio\LaravelInterlink\ServiceProvider\LaravelInterlinkServiceProvider::class
■ Then add the line below to config/app.php > aliases array
'LaravelInterlink' => KaqazStudio\LaravelInterlink\Facade\LaravelInterlinkFacade::class
Initialize Interlink
LaravelInterlink::single();
Initialize Interlink without facade
LaravelInterlink::access();
Laravel Interlink are available on chains! :)
Method | Required | Type | Default | Description |
---|---|---|---|---|
init |
true | chain | Fire the engine | |
setKeyword |
true | string | null | Set target keyword |
setTitle |
false | string | keyword |
Replace with the keyword |
setLink |
true | string | null | Set internal link url |
rawLink |
false | bool | false | Set link url to raw format |
setCount |
false | int | infinite | Count of link replacement |
setPosts |
true | array | null | Set posts collection |
column |
true | string | null | Set content column |
markdown |
false | bool | false | MarkDown format for links |
blank |
false | bool | false | Set links target to _blank |
noFollow |
false | bool | false | Set links rel to nofollow |
setCustomAttributes |
false | string | null | Set custom html attributes for a tag |
process |
true | chain | Process link internalization | |
getUpdatedPosts |
false | chain | Get updated posts as a collection | |
updatePosts |
false | chain | Do update method on all posts |
For example, you want to refer all first AirPods words to /apple-airpods in all of your published Blog posts.
LaravelInterlink::single()
->init() // Warm engine
->setKeyword('AirPods') // Target Keyword
->setLink('/apple-airpods') // Target url
->setCount(1) // For first word
->setPosts(BlogPost::all()) // Get all blog posts
->setColumn('body') // Set `body` column for content target
->process() // Process internalization
->updatePosts(); // Run update on posts!
Also, you can get all updated contents as a collection!
So, you MOST use getUpdatedPosts()
INSTEAD OF updatePosts()
When you need to use your own format for link you can easily do like this
LaravelInterlink::single()
...
->setLink('<a href="own.com">Custom-Link</a>') // Your custom format
->rawLink() // Raw link format [+]
...
Or, Maybe you to add custom html attributes to default link format - "Default a tag"
LaravelInterlink::single()
...
->setCustomAttributes('custom-data="Hello"') // Raw link format [+]
...
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected]
instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.