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

Using event form with relations #43

Closed
invaders-xx opened this issue Aug 4, 2022 · 6 comments · Fixed by #47
Closed

Using event form with relations #43

invaders-xx opened this issue Aug 4, 2022 · 6 comments · Fixed by #47

Comments

@invaders-xx
Copy link
Contributor

I am not able to make it working with an event form using relations : a select or repeater.
Simple form :

protected static function getCreateEventFormSchema(): array
    {
        return [
            Forms\Components\Select::make('planning_id')
                ->label(__('Planning'))
                ->validationAttribute(__('Planning'))
                ->searchable()
                ->relationship('planning', 'name')
                ->preload()
                ->required(),
            Forms\Components\DatePicker::make('start_at')
                ->required(),
            Forms\Components\DatePicker::make('end_at')
                ->default(null),
        ];
    }

I got : Call to a member function planning() on null
Event if the relation exists

@webtamizhan
Copy link

->model(YourModelName::class)

with Select or Repeater.

@invaders-xx
Copy link
Contributor Author

thanks but it's not how it works in that case, we are talking about Repeater and Select which belong to a relation and not a model.

@tiagof
Copy link
Contributor

tiagof commented Aug 25, 2022

->model(YourModelName::class)

with Select or Repeater.

Hi, having this same issue and this solution doesn't seem to work:
using ->model(YourModelName::class) does bypass the exception mentioned in the op, but the relation is not populated nor can be edited.

@invaders-xx did you get it working?

@invaders-xx
Copy link
Contributor Author

@tiagof, I didn't get it working

@tiagof
Copy link
Contributor

tiagof commented Aug 26, 2022

Have a look at #47 .

You'll need to define the below methods, in your Widget class, otherwise you'll still get the exception

class MyWidget extends FullCalendarWidget
{

    protected function getFormModel(): Model|string|null
    {
        return $this->event ?? MyEventModel::class;
    }

    // Resolve Event record into Model property
    public function resolveEventRecord(array $data): MyEventModel
    {
        return MyEventModel::find($data['id']);
    }

@saade, thoughts?

@saade saade closed this as completed in #47 Sep 18, 2022
@invaders-xx
Copy link
Contributor Author

As you reverted #47, it's not working

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

Successfully merging a pull request may close this issue.

3 participants