Data Profiling

The Compass package Data Profiling can be used to implement a view component to link tags or types to specific data models.

Tags view component

Add interface and trait to your data model

First you need to implement the TaggableInterface and Taggable trait to your model class:

class Task extends Model implements TaggableInterface

    use Taggable;

Implementing the interface

The interface has three methods that need to be implemented on the model:

  • The getNameAttribute method is used to get the name of the model.
  • The getDetailsRouteAttribute method is used to get the route of the model.
  • The 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.

Adding the component to the view

The component can be added to the view by using the following code:

<x-compass-data-profiling :model="$task" />

Troubleshooting

For the tags component to work, the following rules apply:

  • The model class must implement the Noardcode\Compass\DataProfiling\Contracts\TaggableInterface interface.
  • The variable passed to the component must be an instance of the model class.