1

On laravel 9 filamenphp site I need to show data in tree and I found this https://github.com/solutionforest/filament-tree plugin.

But source of this plugin is 1 table, not as in my case when I need to combine data from 3 sources and 2 of them are non related tables. If there is a way to load my custom data into this plugin?

I suppose it looks some laravel feature... Has it any

    "filament/filament": "^2.17.39",
    "filament/forms": "^2.17.39",
    "laravel/framework": "^9.52.7",

Thanks in advance!

Petro Gromovo
  • 1,755
  • 5
  • 33
  • 91

1 Answers1

0

It looks like filament-tree does not support this natively. I have had a similar issue.

What I wanted to do was to filter lessons according to the course_id. By default, filament-tree would display all the lessons.

What I wanted was to display in the tree what belongs to a specific course only.

This is what I did.

In the model used by filament-tree, I added a scope.

protected static function boot()
{
    parent::boot();

    static::addGlobalScope('course', function (Builder $builder) {
        $builder->where('course_id', request('course'));
    });
}

You may build your query inside the scope callback. The global scope runs every time you query that model as mentioned here.

HDKT
  • 71
  • 1
  • 8
  • Thank you, but I search a bit different. Not custom filter on some table, but some kind on union, with filtering on 1 table\ – Petro Gromovo Aug 19 '23 at 11:20
  • I am not sure how non-related tables work though. How would you know which data you will need to fetch then? or are you referring to distant relationships? You may want to look into hasManyThrough if you are referring to distant relationship. – HDKT Aug 23 '23 at 05:49