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

Doesn't work inside BelongsToMany field #24

Open
jamespavett opened this issue Apr 29, 2021 · 1 comment
Open

Doesn't work inside BelongsToMany field #24

jamespavett opened this issue Apr 29, 2021 · 1 comment

Comments

@jamespavett
Copy link

jamespavett commented Apr 29, 2021

Trying to use the Items field within a BelongtoMany field, and the inputted values aren't being passed in the request.

BelongsToMany::make('Individual Site Queries', 'sites', SiteResource::class)->fields(function () {
                return [
                    Text::make('Version', 'version')->sortable()->readonly(),
                    Text::make('Query File', 'query_file')->hideWhenCreating()->readonly()->sortable(),
                    Boolean::make('Template Syntax', 'template_syntax')->sortable()->help('Does this query support Array injection via PHP variables?'),
                    Items::make('Headers', 'headers')->draggable(),
                    Code::make('SQL Query')->resolveUsing(function () {
                        return isset($this->pivot) && $this->pivot->query_file ? Storage::get($this->pivot->query_file) : null;
                    })->rules('required')->language('sql')->temporary(),

                ];
            }),

Have tried referencing column via sites.headers and leaving second parameter blank, but always get the same output. No error on frontend however field in database doesn't update. Works outside of BelongsToMany field though just fine.

@jamespavett
Copy link
Author

jamespavett commented Apr 29, 2021

My bad, released I wasn't including the property as part of my withPivot method options. I can now retrieve stores values in the database, but still can't save values.

public function sites()
    {
        return $this->belongsToMany(Site::class)->using(DatabaseQuerySite::class)->withTimestamps()->withPivot([
            'version', 'query_file', 'template_syntax', 'headers'
        ]);
    }

Edit:

In the end I managed to get the values stored in the database by adding the following code inside by saving observer:

$databaseQuerySite->headers = json_decode($this->request->get('headers'));

This isn't needed outside of a BelongsToMany field though, would be good if it could be added a base functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant