1. Go to this page and download the library: Download esign/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/ */
esign / laravel-linkable example snippets
use Esign\Linkable\Concerns\HasDynamicLink;
use Illuminate\Database\Eloquent\Model;
class MenuItem extends Model
{
use HasDynamicLink;
}
Schema::create('menu_items', function (Blueprint $table) {
$table->id();
$table->string('dynamic_link_type')->nullable();
$table->string('dynamic_link_url')->nullable();
$table->string('dynamic_link_linkable_model')->nullable();
});
use Esign\Linkable\Contracts\LinkableUrlContract;
class Post extends Model implements LinkableUrlContract
{
public function linkableUrl(): ?string
{
return "http://localhost/posts/{$this->id}";
}
}
DB::statement('
CREATE OR REPLACE VIEW linkables AS
SELECT
CONCAT("post:", id) AS id,
"post" AS linkable_type,
id AS linkable_id,
CONCAT("Post - ", title) AS label
FROM posts
UNION
SELECT
CONCAT("comment:", id) AS id,
"comment" AS linkable_type,
id AS linkable_id,
CONCAT("Comment - ", title) AS label
FROM comments
');
namespace App\Models\Concerns;
use Esign\Linkable\Concerns\HasDynamicLink as BaseHasDynamicLink;
trait HasDynamicLink
{
use BaseHasDynamicLink {
dynamicLink as baseDynamicLink;
}
public static string $linkTypeAnchor = 'anchor';
public function dynamicLink(): ?string
{
return match ($this->dynamicLinkType()) {
static::$linkTypeAnchor => $this->dynamicLinkUrl(),
default => $this->baseDynamicLink(),
};
}
}
namespace App\View\Components;
use App\Models\Concerns\HasDynamicLink;
use Esign\Linkable\View\Components\DynamicLink as BaseDynamicLink;
class DynamicLink extends BaseDynamicLink
{
public function render(): ?View
{
return match ($this->model->dynamicLinkType()) {
HasDynamicLink::$linkTypeAnchor => view('linkable.dynamic-link-anchor'),
default => parent::render(),
};
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.