erikms61
Reuse resource form in another livewire component
The thing I really hate about this is that the activity already exists, or I can't show it. I'd have preferred something like ->form(ActivityResource::getFormFields())
...feed that the just-created object and the form would be filled
17 replies
Reuse resource form in another livewire component
ok... my problem was: I have a table of locations that have stocklevels, and I wanted to have a button saying "restock". Then the Model determines how much and from where, and creates a User Activity to go get those stock items. So far so good.
However, once the Activity has been created, (or
new
d, preferably), I wanted the user to be able to review the Activity before saving it.
...But I already had a form for than, and I don't want to duplicate that code.
so this is my solution:
17 replies
Reuse resource form in another livewire component
Hi Jacques,
I notice that your district_id, councilors and votes fields are all null; are they table relations?
I have a similar problem: when I try to reuse the form, Filament breaks on table relationships.
17 replies
Reuse the form schema in resource to call it from action buttons around
Hi, I'm not sure if I'm breaking etiquette by replying to this old thread, but I have a similar problem as Albert.
I managed to get pretty far in solving it, but now I seem to be stuck.
I have a LocationRescource, with an Action on the table rows to replenish stock at the Location. When the action is triggered, this creates an Activity. I then want the user to be able to edit the Activity, re-using the ActivityResource form fields. So far so good.
However, the Activity form contains relationships, and somehow these cannot deal with relationships on the Activity object.
//LocationResource.php
Action::make('Restock')
->model(ActivityResource::getModel())
->form([
TextInput::make('description'),
DatePicker::make('due_date'),
DatePicker::make('planned_date'),
TextInput::make('priority')->numeric(),
Select::make('status_id')->options(
ActivityStatus::all()->pluck('name', 'id')
)->relationship('Status', 'name'),
])
->mountUsing(function (Form $form, LocationStock $record) {
$activity = $record->replenish();
$form->fill($activity->toArray());
}),
If I remove the Select from the form, everything is fine. Put it in, I get "Call to a member function getResults() on null"
Any ideas?39 replies