The Compass package Data Profiling can be used to implement a view component to link tags or types to specific data models.
First you need to implement the TaggableInterface and Taggable trait to your model class:
class Task extends Model implements TaggableInterface
use Taggable;
The interface has three methods that need to be implemented on the model:
getNameAttribute
method is used to get the name of the model.getDetailsRouteAttribute
method is used to get the route of the model.supportedTagTypes
method is used to get the types that are supported by the model. public function getNameAttribute(): ?string
{
return $this->title;
}
public function getDetailsRouteAttribute(): ?string
{
return route('admin.tasks.show', $this);
}
public static function supportedTagTypes(): null|string|array
{
return 'task';
}
This is an example based on the Task model.
The component can be added to the view by using the following code:
<x-compass-data-profiling :model="$task" />
For the tags component to work, the following rules apply:
Noardcode\Compass\DataProfiling\Contracts\TaggableInterface
interface.