CodeWithDennis / filament-select-tree

The multi-level select field lets you pick one or multiple options from a list that is neatly organized into different levels.
MIT License
207 stars 28 forks source link

How to start using the package in resource file? #39

Closed sergeynilov closed 10 months ago

sergeynilov commented 10 months ago

I need to make some tree with data based on datas from 3 db tables categories - has id, name fields, user_quiz_requests - has quiz_category_id and user_email fields users - has id, email fields

I tried to make a container resource with command :

php artisan make:filament-resource UserQuizRequestTree

I have installed "^3.1.18" on laravel 10.31.0 / filament ^3.0-stable app.

But inserting SelectTree into generated UserQuizRequestTreeResource.php file in “table” block:

<?php

namespace App\Filament\Resources;

use App\Filament\Resources\UserQuizRequestTreeResource\Pages;
use App\Filament\Resources\UserQuizRequestTreeResource\RelationManagers;
use App\Models\QuizCategory;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use CodeWithDennis\FilamentSelectTree\SelectTree;

class UserQuizRequestTreeResource extends Resource
{
    protected static ?string $model = QuizCategory::class;

    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                //
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([

                \CodeWithDennis\FilamentSelectTree\SelectTree::make('userQuizRequests')
                    ->relationship('userQuizRequests', 'user_name', 'quiz_category_id', function ($query) {
                        return $query;
                    })
            ])
            ->filters([

I got error :

Method CodeWithDennis\FilamentSelectTree\SelectTree::table does not exist. What must be a container for SelectTree component and how to start using it ?

mszabeh commented 10 months ago

Why you use it in $table ->columns ?

SelectTree is a filed and you must use it in $form or in table filters

CodeWithDennis commented 10 months ago

This is not how it works, the SelectTree is a field for your forms or filters. Besides that it only supports BelongsTo and BelongsToMany. Take a look at the Filament documentation for some insights into forms. Also, consider checking out Laravel relations – it's worth a peek!