erikms61
erikms61
FFilament
Created by Jacques on 11/19/2023 in #❓┊help
Reuse resource form in another livewire component
I'd appreciate that; when I dig into the Filament basics, it seems that the ->relation() field is not being propagated
17 replies
FFilament
Created by Jacques on 11/19/2023 in #❓┊help
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
FFilament
Created by Jacques on 11/19/2023 in #❓┊help
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:
Action::make('move_stock')
->mountUsing(
function (LocationStock $record) {
$activity = null;
$stock = $record->getCurrentStock();
if($stock < $record->maximum) {
$activity = $record->replenish();
}
if($stock > $record->maximum) {
$activity = $record->moveOut();
}
if(!is_null($activity)) {
$activity->save();
*return redirect(route('filament.admin.resources.activities.edit', $activity->id));*
}
}
),
Action::make('move_stock')
->mountUsing(
function (LocationStock $record) {
$activity = null;
$stock = $record->getCurrentStock();
if($stock < $record->maximum) {
$activity = $record->replenish();
}
if($stock > $record->maximum) {
$activity = $record->moveOut();
}
if(!is_null($activity)) {
$activity->save();
*return redirect(route('filament.admin.resources.activities.edit', $activity->id));*
}
}
),
17 replies
FFilament
Created by Jacques on 11/19/2023 in #❓┊help
Reuse resource form in another livewire component
I solved it by creating the record, then redirecting the user to the edit url... ugly and hacky but it works
17 replies
FFilament
Created by Jacques on 11/19/2023 in #❓┊help
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
FFilament
Created by erikms61 on 11/10/2023 in #❓┊help
Reused form fields do not seem to follow model relationships
bump
3 replies
FFilament
Created by Albert Lens on 9/5/2023 in #❓┊help
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