Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelectTree Component Does Not Save Parent Area in Database #93

Closed
zeyadsharo opened this issue Mar 12, 2024 · 1 comment
Closed

SelectTree Component Does Not Save Parent Area in Database #93

zeyadsharo opened this issue Mar 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@zeyadsharo
Copy link

What happened?

SelectTree component, when used in the AreaResource, does not save the selected parent area into the database. There are no error messages displayed, making it difficult to diagnose the issue.

Component/Area:

 public static function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput::make('arabic_title')->required(),
                TextInput::make('kurdish_title')->required(),
              
                SelectTree::make('parentArea')
                     ->relationship('parentArea', 'arabic_title', 'parent_id')
                     ->placeholder(__('Please select a Area'))
                ->withCount()
                ->direction('buttom')
                     ->label(__('Parent Area'))->nullable(),
                TextInput::make('latitude')
                    ->required()
                    ->rules('numeric'),
                TextInput::make('longitude')
                    ->required()
                    ->rules('numeric'),
            ]);
    }

Model:

class Area extends Model
{
    use HasFactory;
    protected $fillable = [
        'arabic_title', 'kurdish_title', 'parent_id', 'latitude', 'longitude'
    ];

    public function parentArea()
    {
        return $this->belongsTo(Area::class, 'parent_id');
    }
}

migration:

Schema::create('areas', function (Blueprint $table) {
            $table->id();
            $table->string('arabic_title');
            $table->string('kurdish_title');
            $table->unsignedBigInteger('parent_id')->nullable();
            $table->foreign('parent_id')->references('id')->on('areas')->onDelete('cascade');
            $table->decimal('latitude', 13, 9);
            $table->decimal('longitude', 13, 9);
            $table->timestamps();
        });

image

How to reproduce the bug

Steps to Reproduce:

  1. Go to the AreaResource form in the application.
  2. Use the SelectTree to choose a parent area.
  3. Save the form.
  4. Check the database or refresh the form; the parent area is not updated in the database.

Expected Result:
The selected parent area should be saved into the database and be visible when retrieving or refreshing the Area details.

Actual Result:
The parent area selection is not saved into the database, and no errors are displayed, indicating a silent failure.

Package Version

3.1

PHP Version

8.1

Laravel Version

10.10

Which operating systems does with happen with?

Windows

Notes

No response

@zeyadsharo zeyadsharo added the bug Something isn't working label Mar 12, 2024
@CodeWithDennis
Copy link
Owner

Since parentArea is a BelongsTo im assuming it saves a single ID to this column? Try adding parentArea to your fillable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants