- How do I add a tags field to a Laravel Nova resource?
- First, ensure your Eloquent model uses the `HasTags` trait from spatie/laravel-tags. Then, add the `Tags::make('Tags')` field to your Nova resource’s `fields()` method. The package handles the rest, storing tags in the shared `tags` table.
- Does spatie/nova-tags-field work with Laravel Nova 4 or 5?
- Yes, the package supports both Nova 4.x and 5.x. Always check the package’s documentation for version-specific requirements, as minor updates may align with newer Nova releases. Compatibility is typically maintained for the latest stable Nova versions.
- Can I use this package without spatie/laravel-tags already installed?
- No, you must install `spatie/laravel-tags` separately as it powers the tagging functionality. Follow the [installation guide](https://spatie.be/docs/laravel-tags/v4/installation-and-setup) to set up the tags table and model before using `spatie/nova-tags-field`.
- Will this package slow down Nova if I have thousands of tags?
- Performance depends on your database and Nova’s UI. The package uses a pivot-table approach, which is efficient for most use cases. For large datasets, consider indexing the `tags` table or optimizing Nova’s query filters to avoid loading excessive tag data.
- Can I customize the tag input UI in Nova?
- Basic customization is possible via Nova’s field options, but heavy UI changes may require overriding the package’s Vue.js components. Check the `vendor:publish` command to access the package’s assets for deeper customization.
- How do I filter Nova resources by tags?
- Use Eloquent’s `whereHas` method in your Nova resource’s `scope` or `query` methods. For example, `return $query->whereHas('tags', function ($query) { $query->where('name', 'like', '%keyword%'); });`. The package ensures tags are queryable via the `HasTags` trait.
- Does this package support PostgreSQL?
- While `spatie/laravel-tags` supports PostgreSQL, `spatie/nova-tags-field` is primarily tested with MySQL 5.7.8+. PostgreSQL may require adjustments, such as customizing the pivot table schema or handling JSON tag storage if needed.
- Can I use this with Laravel 8 or 9?
- Yes, the package works with Laravel 8+ as long as your Nova version is compatible. Ensure `spatie/laravel-tags` (v3.x+) is installed, which supports these Laravel versions. Always verify dependencies for version conflicts.
- Are there alternatives to spatie/nova-tags-field for Nova tagging?
- Yes, alternatives include custom Nova fields using Laravel’s `many-to-many` relationships or packages like `beberlei/laravel-nova-tags`. However, `spatie/nova-tags-field` integrates seamlessly with `spatie/laravel-tags`, offering a mature, feature-rich solution with minimal setup.
- How do I test tag functionality in my Nova resource?
- Test by creating a Nova resource with the `Tags` field, then verify tag creation, editing, and deletion in the UI. Backend tests should include assertions for Eloquent queries like `model->tags`, `model->tag('name')`, and `whereHas('tags')` to ensure data integrity.