1. Go to this page and download the library: Download wezlo/filament-lookups 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/ */
wezlo / filament-lookups example snippets
use Wezlo\FilamentLookups\FilamentLookupsPlugin;
$panel
->plugin(FilamentLookupsPlugin::make()
->navigationGroup('Settings'));
namespace App\Lookups;
use Illuminate\Database\Eloquent\Model;
use Wezlo\FilamentLookups\Lookup;
class Countries extends Lookup
{
public function name(): string
{
return 'Countries';
}
public function description(): ?string
{
return 'List of supported countries';
}
public function isHierarchical(): bool
{
return false;
}
public function canAdd(): bool
{
return true;
}
public function canEdit(?Model $record = null): bool
{
return true;
}
public function canDelete(?Model $record = null): bool
{
return false; // protect country values from deletion
}
}
use Illuminate\Database\Eloquent\Model;
use Wezlo\FilamentLookups\Lookup;
class OrderStatus extends Lookup
{
public function canEdit(?Model $record = null): bool
{
// prevent editing system-defined statuses
return ! $record?->metadata['is_system'];
}
public function canDelete(?Model $record = null): bool
{
// only allow deleting statuses that are not in use
return $record?->orders()->doesntExist() ?? true;
}
}
use Wezlo\FilamentLookups\Forms\Components\LookupSelect;
LookupSelect::make('country_id')
->lookupType('countries')