PHP code example of outerweb / filament-link-picker

1. Go to this page and download the library: Download outerweb/filament-link-picker 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/ */

    

outerweb / filament-link-picker example snippets


use OuterWeb\FilamentLinkPicker\Filament\FilamentLinkPicker;

class FilamentPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugins([
                FilamentLinkPickerPlugin::make(),
            ]);
    }
}

FilamentLinkPickerPlugin::make()
    ->disableExternalLinks();

FilamentLinkPickerPlugin::make()
    ->disableMailto();

FilamentLinkPickerPlugin::make()
    ->disableTel();

FilamentLinkPickerPlugin::make()
    ->disableDownload();

FilamentLinkPickerPlugin::make()
    ->disableOpenInNewTab();

FilamentLinkPickerPlugin::make()
    ->translateLabels();

Route::get('/your-route/{parameter}', YourController::class)
    ->name('your-route')
    ->filamentLinkPicker(
        label: 'your-route.label',
        group: 'your-route.group',
        parameterLabels: [
            'parameter' => 'your-route.parameter',
        ]
    );

use Illuminate\Support\Facades\Route;

Route::get('/your-route', YourController::class)
    ->name('your-route')
    ->filamentLinkPicker();

Route::get('/your-route', YourController::class)
    ->name('your-route')
    ->filamentLinkPicker(
        label: 'Your custom label'
    );

Route::get('/your-route', YourController::class)
    ->name('your-route')
    ->filamentLinkPicker(
        group: 'Your custom group'
    );

Route::get('/your-route', YourController::class)
    ->name('your-route')
    ->filamentLinkPicker(
        isLocalized: true
    );

Route::get('/your-route/{parameter}', YourController::class)
    ->name('your-route')
    ->filamentLinkPicker(
        parameterLabels: [
            'your-parameter' => 'Your parameter label'
        ]
    );

Route::get('/your-route/{parameter}', YourController::class)
    ->name('your-route')
    ->filamentLinkPicker(
        parameterOptions: [
            'your-parameter' => [
                'option1' => 'Option 1',
                'option2' => 'Option 2',
            ]
        ]
    );

Route::get('/event/{event:slug}', 'show')->name('show')->filamentLinkPicker(
        label: 'Single Event',
        group: 'Details Page',
        parameterModelKeys: [
            'event' => 'slug',
        ]
    );

class YourModel extends Model
{
    public function getLinkPickerLabel(): string
    {
        return $this->your_attribute;
    }
}

class YourModel extends Model
{
    public string $linkPickerLabel = 'your_attribute';
}

class YourModel extends Model
{
    public function scopeLinkPickerOptions(Builder $query): void
    {
        // Your query here
    }
}

Route::get('/your-route', YourController::class)
    ->name('your-route')
    ->filamentLinkPicker(
        isLocalized: true
    );

use Outerweb\FilamentLinkPicker\Entities\LinkPickerRoute;

FilamentLinkPickerPlugin::make()
    ->combineLocalizedRoutesUsing(function (LinkPickerRoute $route): LinkPickerRoute {
        // Imagine your routes are named like `en.your-route` and `nl.your-route`
        // We want to combine these routes so that the link picker only shows one option for `your-route`
        return $route->name(Str::after($route->name(), '.'));
    });

use Outerweb\FilamentLinkPicker\Entities\LinkPickerRoute;

FilamentLinkPickerPlugin::make()
    ->buildLocalizedRouteUsing(function (string $name, array $parameters = [], bool $absolute = true, ?string $locale = null): ?string {
        // If you use our `outerweb/localization` package,
        // You can use the `localizedRoute` helper.
        return localizedRoute($name, $parameters, $absolute, $locale);
    });

use Outerweb\FilamentLinkPicker\Casts\LinkCast;

class YourModel extends Model
{
    protected $casts = [
        'link' => LinkCast::class,
    ];
}

use Outerweb\FilamentLinkPicker\Facades\LinkPicker;

$link = LinkPicker::dataToLinkEntity(array $data);