PHP code example of altwaireb / filament-title-and-slug
1. Go to this page and download the library: Download altwaireb/filament-title-and-slug 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/ */
altwaireb / filament-title-and-slug example snippets
TitleAndSlugInput::make(
fieldTitle: 'title', // The name of the field in your model that stores the title.
fieldSlug: 'slug', // The name of the field in your model that will store the slug.
),
use \Altwaireb\Filament\Forms\Components\TitleAndSlugInput;
class PostResource extends Resource
{
public static function form(Form $form): Form
{
return $form->schema([
TitleAndSlugInput::make(
fieldTitle: 'title',
fieldSlug: 'slug',
)
]);
}
}
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
fieldTitle: 'name',
fieldSlug: 'identifier',
)
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
urlPath: '/book/',
urlVisitLinkLabel: 'Visit Book',
titleLabel: 'Title',
titlePlaceholder: 'Insert the title...',
slugLabel: 'Link:',
)
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
urlHostVisible: false,
)
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
urlPath: '/category/',
urlHost: 'https://project.local',
)
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
urlPath: '/product/',
urlHost: 'camya.com',
urlVisitLinkRoute: fn(?Model $record) => $record?->slug
? route('product.show', ['slug' => $record->slug])
: null,
)
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
urlVisitLinkVisible: false,
)
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
titleExtraInputAttributes: ['class' => 'italic'],
)
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
titleRules: [
'
protected $messages = [
'data.slug.regex' => 'Invalid Slug. Use only chars (a-z), numbers (0-9), and the dash (-).',
];
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
titleRuleUniqueParameters: [
'callback' => fn(Unique $rule) => $rule->where('is_published', 1),
'ignorable' => fn(?Model $record) => $record,
],
)
'ignorable' (Model | Closure)
'callback' (?Closure)
'ignoreRecord' (bool)
'table' (string | Closure | null)
'column' (string | Closure | null)
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
slugSlugifier: fn($string) => preg_replace( '/[^a-z]/', '', $string),
slugRuleRegex: '/^[a-z]*$/',
)
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
slugRules: [],
),
\Filament\Forms\Components\Repeater::make('FAQEntries')
->relationship()
->collapsible()
->schema([
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
fieldTitle: 'title',
fieldSlug: 'slug',
urlPath: '/faq/',
urlHostVisible: false,
titleLabel: 'Title',
titlePlaceholder: 'Insert FAQ title...'
)
]),
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
urlPath: '/books/',
urlVisitLinkRoute: fn (?Model $record) => $record?->slug
? '/books/'.$record->slug.'/detail'
: null,
slugLabelPostfix: '/detail/',
urlVisitLinkLabel: 'Visit Book Details'
),
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
fieldSlug: 'subdomain',
urlPath: '',
urlHostVisible: false,
urlVisitLinkLabel: 'Visit Domain',
urlVisitLinkRoute: fn (?Model $record) => $record?->slug
? 'https://'.$record->slug.'.camya.com'
: null,
slugLabel: 'Domain:',
slugLabelPostfix: '.camya.com',
),
[
'field_title' => 'title', // Overwrite with (fieldTitle: 'title')
'field_slug' => 'slug', // Overwrite with (fieldSlug: 'title')
'url_host' => env('APP_URL'), // Overwrite with (urlHost: 'https://www.camya.com/')
];
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
fieldTitle: 'title',
fieldSlug: 'slug',
);
\Altwaireb\Filament\Forms\Components\TitleAndSlugInput::make(
// Model fields
fieldTitle: 'title',
fieldSlug: 'slug',
// Url
urlPath: '/blog/',
urlHost: 'https://www.camya.com',
urlHostVisible: true,
urlVisitLinkLabel: 'View',
urlVisitLinkRoute: fn(?Model $record) => $record?->slug
? route('post.show', ['slug' => $record->slug])
: null,
urlVisitLinkVisible: true,
// Title
titleLabel: 'The Title',
titlePlaceholder: 'Post Title',
titleExtraInputAttributes: ['class' => 'italic'],
titleRules: [
'd) => $record,
],
slugIsReadonly: fn($context) => $context !== 'create',
slugSlugifier: fn($string) => Str::slug($string),
slugRuleRegex: '/^[a-z0-9\-\_]*$/',
slugAfterStateUpdated: function ($state) {},
slugLabelPostfix: null,
)->columnSpan('full'),
bash
php artisan vendor:publish --tag="filament-title-and-slug-translations"