prowler
prowler
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
on the last step it creates another new rfq and being redirected to its edit page with no assembly(ies) attached to it. how can i prevent the submit on the last step, or at least control it more granularly?
16 replies
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
actually no.. its still not working. ugh.
16 replies
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
i managed to solve it with some public variables on the CreateRfq itself which then I pass between each step and attaching this relationship on the step's afterValidation() function, for example -
Step::make('RFQ')
->schema($this->getRfqFormSchema())
->afterValidation(function ($state, callable $set, callable $get) {
$this->rfq = Rfq::create($state);
$this->rfqId = $this->rfq->id;

})->model(Rfq::class),
Step::make('Assemblies')
->schema($this->getAssemblyFormSchema($this->rfqId))
->afterValidation(function ($state, callable $set) {
$this->assembly = Assembly::create($state);
$this->assembly->rfq_id = $this->rfqId;
logger("Assembly {$this->assembly->name} ({$this->assembly->id}) was created and its parent rfq is {$this->assembly->rfq->name}");
})->model(Assembly::class),
Step::make('RFQ')
->schema($this->getRfqFormSchema())
->afterValidation(function ($state, callable $set, callable $get) {
$this->rfq = Rfq::create($state);
$this->rfqId = $this->rfq->id;

})->model(Rfq::class),
Step::make('Assemblies')
->schema($this->getAssemblyFormSchema($this->rfqId))
->afterValidation(function ($state, callable $set) {
$this->assembly = Assembly::create($state);
$this->assembly->rfq_id = $this->rfqId;
logger("Assembly {$this->assembly->name} ({$this->assembly->id}) was created and its parent rfq is {$this->assembly->rfq->name}");
})->model(Assembly::class),
16 replies
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
Also, for some reason, im now missing the 'previous' button on the wizard. Only Next and Cancel are there
16 replies
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
Assembly.php -
public function rfq(): BelongsTo
{
return $this->belongsTo(Rfq::class);
}
public function rfq(): BelongsTo
{
return $this->belongsTo(Rfq::class);
}
Rfq.php
public function assemblies(): HasMany
{
return $this->hasMany(Assembly::class);
}
public function assemblies(): HasMany
{
return $this->hasMany(Assembly::class);
}
Basically, on the second step there should be some sort of a repeater for the assemblies while each of them should automatically derive the rfq's id that was created on the first step so eventually i won't have this field visible to the user since the rfq was already 'chosen' on the previous step - Assembly.php - getForm() function -
Select::make('rfq_id')
->options(fn () => Rfq::all()->pluck('name', 'id')->toArray())
->required(), //this is here only for debugging purposes atm

Forms\Components\TextInput::make('name')
->maxLength(255),
Forms\Components\TextInput::make('number')
->required()
->maxLength(255),
// more fields...
Select::make('rfq_id')
->options(fn () => Rfq::all()->pluck('name', 'id')->toArray())
->required(), //this is here only for debugging purposes atm

Forms\Components\TextInput::make('name')
->maxLength(255),
Forms\Components\TextInput::make('number')
->required()
->maxLength(255),
// more fields...
Thanks again @awcodes for your time. It's not taken for granted!
16 replies
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
And on the assembly form there's a select field with a relationship to rfq -
Select::make('rfq_id')
->options(fn () => Rfq::all()->pluck('name', 'id')->toArray())
->required()
Select::make('rfq_id')
->options(fn () => Rfq::all()->pluck('name', 'id')->toArray())
->required()
(the reason i didn't use ->relationship('rfq','name') because it tries to load this relationship on the rfq create page and obviously its wrong because rfq doesn't have a relationship called rfq as well) I hoped I could somehow patch it by creating a real rfq on the first step -
->afterValidation(function ($state, callable $set, callable $get) {
$this->rfq = Rfq::create($state);
})->model(Rfq::class)
->afterValidation(function ($state, callable $set, callable $get) {
$this->rfq = Rfq::create($state);
})->model(Rfq::class)
And then pass this rfq's id to the next step like this -
->afterStateUpdated(function ($state, callable $set) {
$set('rfq_id', $this->rfq?->id);
})
->afterStateUpdated(function ($state, callable $set) {
$set('rfq_id', $this->rfq?->id);
})
But sadly it doesn't work and because both forms share some attributes with the same name (e.g. name) then when moving to step 2 it basically derives the name of the rfq from step 1 because the wizard sees all these forms as one big form and not as separate ones. Hope i was clear and provided enough info
16 replies
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
$this->getRfqFormSchema() returns an array -
[
Forms\Components\Section::make('General Information')
->columns()
->icon('heroicon-o-information-circle')
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\Select::make('user_id')
->relationship('user','name')
->preload()
->searchable(),
Forms\Components\Select::make('customer_id')
->relationship('customer','name')
->preload()
->searchable(), // ... more fields
]
[
Forms\Components\Section::make('General Information')
->columns()
->icon('heroicon-o-information-circle')
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\Select::make('user_id')
->relationship('user','name')
->preload()
->searchable(),
Forms\Components\Select::make('customer_id')
->relationship('customer','name')
->preload()
->searchable(), // ... more fields
]
16 replies
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
sadly i can't share the whole repo so i'll paste some crucial pieces to understand the overall concept - I have a resource called RfqResource and its create page with a wizard and these are the steps -
protected function getSteps(): array
{
return [
Step::make('RFQ')
->schema($this->getRfqFormSchema())
->afterValidation(function ($state, callable $set, callable $get) {
$this->rfq = Rfq::create($state);
})->model(Rfq::class),
Step::make('Assemblies')
->schema($this->getAssemblyFormSchema(1))
->afterStateUpdated(function ($state, callable $set) {
$set('rfq_id', $this->rfq?->id);
})
->afterValidation(function ($state, callable $set) {
$this->assembly = Assembly::create($state);
$set('assembly_id', $this->assembly?->id);

})->model(Assembly::class),
Step::make('BOM')
->schema($this->getBomFormSchema())
->afterStateHydrated(function ($state, callable $set) {
$set('assembly_id', $this->assembly?->id);
})->model(Bom::class),
];
}
protected function getSteps(): array
{
return [
Step::make('RFQ')
->schema($this->getRfqFormSchema())
->afterValidation(function ($state, callable $set, callable $get) {
$this->rfq = Rfq::create($state);
})->model(Rfq::class),
Step::make('Assemblies')
->schema($this->getAssemblyFormSchema(1))
->afterStateUpdated(function ($state, callable $set) {
$set('rfq_id', $this->rfq?->id);
})
->afterValidation(function ($state, callable $set) {
$this->assembly = Assembly::create($state);
$set('assembly_id', $this->assembly?->id);

})->model(Assembly::class),
Step::make('BOM')
->schema($this->getBomFormSchema())
->afterStateHydrated(function ($state, callable $set) {
$set('assembly_id', $this->assembly?->id);
})->model(Bom::class),
];
}
each of these getBomFormSchema() functions basically returns an array with the whole scheme, for example -
16 replies
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
sorry if pinging you is considered rude
16 replies
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
@awcodes - when searching for 'wizard' here in discord i saw that you wrote to someone - You’re trying to use the wizard as a multiple form instead of steps in a form so it going to require a more granular custom approach.. Do you mind sharing any direction for that? Im struggling to manage a wizard with 3 steps where each step should handle a different form for a different resource, but still no success.
16 replies
FFilament
Created by prowler on 7/5/2024 in #❓┊help
Is it possible to manage different resources (models) on each Step inside a Wizard?
Anyone, please?
16 replies
FFilament
Created by prowler on 6/30/2024 in #❓┊help
Passing closure in viewData
Ideally what i'd want to is be able to do something like this -
Forms\Components\View::make('engines')
->viewData(function(Get $get) {
return [
'formValues' => [
'title' => $get('title'),
'subtitle' => $get('subtitle'),
'button_text' => $get('button_text'),
'content' => $get('content'),
];
})
Forms\Components\View::make('engines')
->viewData(function(Get $get) {
return [
'formValues' => [
'title' => $get('title'),
'subtitle' => $get('subtitle'),
'button_text' => $get('button_text'),
'content' => $get('content'),
];
})
4 replies
FFilament
Created by prowler on 6/25/2024 in #❓┊help
Passing the record in the helperText method
yeah, i made some confusion there thinking that the $record in this case is the record chosen from the Select component (content_type_variation_id). My bad. Thanks for clarifying it
7 replies
FFilament
Created by prowler on 6/25/2024 in #❓┊help
Passing the record in the helperText method
Forms\Components\Select::make('content_type_variation_id')
->helperText(function (Forms\Get $get) {
if ($get('content_type_variation_id')) {
$contentTypeVariationId = $get('content_type_variation_id');
$sampleArticles = Article::whereHas('brief', function ($query) use ($contentTypeVariationId) {
$query->where('content_type_variation_id', $contentTypeVariationId);
})->isSample()->get();
if(count($sampleArticles) > 0) {
$urls = $sampleArticles->map(function ($article, $key) {
return '<a style="color: #0044cc;" class="font-semibold" target="_blank" href="' . route('article.preview', $article->slug) . '">Sample #' . $key+1 . '</a>';
});
return new HtmlString($urls->implode(' / '));
}
else {
return 'No samples available for the selected content type variation.';
}
}
return 'No samples available for the selected content type variation.';
})
Forms\Components\Select::make('content_type_variation_id')
->helperText(function (Forms\Get $get) {
if ($get('content_type_variation_id')) {
$contentTypeVariationId = $get('content_type_variation_id');
$sampleArticles = Article::whereHas('brief', function ($query) use ($contentTypeVariationId) {
$query->where('content_type_variation_id', $contentTypeVariationId);
})->isSample()->get();
if(count($sampleArticles) > 0) {
$urls = $sampleArticles->map(function ($article, $key) {
return '<a style="color: #0044cc;" class="font-semibold" target="_blank" href="' . route('article.preview', $article->slug) . '">Sample #' . $key+1 . '</a>';
});
return new HtmlString($urls->implode(' / '));
}
else {
return 'No samples available for the selected content type variation.';
}
}
return 'No samples available for the selected content type variation.';
})
Basically, it works but if i could get the $record in the closure - i'd have much less code as i could directly check for $record's relationship
7 replies
FFilament
Created by prowler on 6/25/2024 in #❓┊help
Passing the record in the helperText method
i managed to solve it with some workaround using the Get $get approach, but still, i wonder why some methods are able to get the $record and some not.
7 replies
FFilament
Created by prowler on 6/20/2024 in #❓┊help
Relocate Search Field in Table Builder
thank you both
9 replies
FFilament
Created by prowler on 6/20/2024 in #❓┊help
Relocate Search Field in Table Builder
anyone, please?
9 replies
FFilament
Created by prowler on 6/20/2024 in #❓┊help
Relocate Search Field in Table Builder
No description
9 replies
FFilament
Created by Abdellah on 6/9/2024 in #❓┊help
Dispatch event in lifecycle hook
is the event queueable? if so, is there a worker running to process it?
4 replies
FFilament
Created by prowler on 6/9/2024 in #❓┊help
Filament is saving relationship only on edit (update) pages but not on create.
ok, i spotted something interesting.. not sure if its a bug in filament/livewire or just a bad architecture by myself. my whole $form has a disabled function attached to it conditionally in this way -
return $form
->schema([ ... ])
->disabled(fn (?Brief $record): bool => $record?->status === BriefStatusEnum::Processing->value);
return $form
->schema([ ... ])
->disabled(fn (?Brief $record): bool => $record?->status === BriefStatusEnum::Processing->value);
Once the form is disabled - all its relationships aren't being saved. Once I remove this disabled condition - it all works just fine.
5 replies