FilamentF
Filamentβ€’13mo ago
Matthew

JSON relationship column in table

I have a table with a JSON column, like this:
Schema::create('filament-latex', function (Blueprint $table) {
    $table->id();
    // ...
    $table->json('collaborators_id')->nullable();
    // ...
    $table->timestamps();
});

In my model, I cast it as an array:
protected $fillable = ['collaborators_id']; /// other columns omitted
protected $table = 'filament-latex';
protected $casts = [
    'collaborators_id' => 'array',
];

And in my resource table,
TextColumn::make('collaborators')
    ->label('Collaborators')
    ->visible(! config('filament-latex.avatar-columns'))
    ->badge()
    ->color('info'),

Using tinker, the column is saved on my table like this:
collaborators_id: "["4","5"]",

How should I define my relationship such that the resource table shows the name of the users? I havent used relationships that much so Im a bit confused πŸ˜…
Was this page helpful?