Spatie tag name text input field

Hello all, I have created a resource for the spatie tag model:
use Spatie\Tags\Tag;

class TagResource extends Resource
{
protected static ?string $model = Tag::class;

protected static ?string $navigationIcon = 'heroicon-o-tag';

public static function form(Form $form): Form
{
return $form
->schema([
Section::make()
->schema([
Forms\Components\TextInput::make('name')
->label('Name')
->translateLabel()
->required()
->unique('name', 'tags')
->maxLength(255),
use Spatie\Tags\Tag;

class TagResource extends Resource
{
protected static ?string $model = Tag::class;

protected static ?string $navigationIcon = 'heroicon-o-tag';

public static function form(Form $form): Form
{
return $form
->schema([
Section::make()
->schema([
Forms\Components\TextInput::make('name')
->label('Name')
->translateLabel()
->required()
->unique('name', 'tags')
->maxLength(255),
I want the user to be able to change the name of the tag, the problem is that it is saved like the following: {"nl": "test"}. So with the above code I get [object Object], and when I try to submit it, I get the following errror: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database.name' doesn't exist. Then I tried to do the form like this.
Forms\Components\TextInput::make('name.nl')
->label('Name')
->translateLabel()
->required()
->unique('name', 'tags')
->maxLength(255),
Forms\Components\TextInput::make('name.nl')
->label('Name')
->translateLabel()
->required()
->unique('name', 'tags')
->maxLength(255),
This did fill the field with the string I wanted it to fill with, but still the same error ocurs. Any help would be really appreciated.
4 Replies
toeknee
toeknee5w ago
Are you using the original model or a new model?
Tjiel
Tjiel5w ago
@toeknee im using the original model
Lara Zeus
Lara Zeus5w ago
spatie tags uses HasTranslations by default for the slug and the name public array $translatable = ['name', 'slug']; so you may need to install https://larazeus.com/translatable
Tjiel
Tjiel4w ago
Found the solution I was stupid and it was because of the unique, the name and tags should be the other way around.
Forms\Components\TextInput::make('name.nl')
->label('Name')
->translateLabel()
->required()
->unique('tags', 'name')
->maxLength(255),
Forms\Components\TextInput::make('name.nl')
->label('Name')
->translateLabel()
->required()
->unique('tags', 'name')
->maxLength(255),
Want results from more Discord servers?
Add your server