Forms\Components\TextInput::make('slug') ->hint('Translatable') ->hintColor('primary') ->hintIcon('heroicon-m-language') ->disabled() ->rules([ function () { return function ($value, Closure $fail, $livewire) { // Check if slug belongs to currrent page $count = Sitemap::all() ->where('slug', '=', $value) ->where('resource_id', $livewire->record->getAttribute('id')) ->where('resource_type', 'page') ->count(); if ($count > 0) { return; } // Check if slug already exists in another resource $countExists = Sitemap::all() ->where('slug', '=', $value) ->count(); if ($countExists > 0) { $fail("The slug already exists in another resource"); } }; }, ]) ->maxLength(255),