Joachim Strand
Joachim Strand
FFilament
Created by Joachim Strand on 5/1/2024 in #❓┊help
Tenant user pivot values
Hey, I have a fairly standard tenant setup and I have a users resource to show the tenant users. My "tenant" is a Company. So a company belongsToMany Users and a users belongsToMany Companies with the pivot table having a column role. Listing the users is working just fine, but the role is not showing (or none of the pivot values). This is the relationship on the Users model:
public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class)
->withTimestamps()
->withPivot([
'created_at',
'updated_at',
'role',
'added_by_user_id',
])
->using(CompanyUserPivot::class);
}
public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class)
->withTimestamps()
->withPivot([
'created_at',
'updated_at',
'role',
'added_by_user_id',
])
->using(CompanyUserPivot::class);
}
I have the same thing on the Company model, just the reverse users(). I have a pivot class that is casting the role to a enum and the added_by_user_id is a relationship to a user. I understand that I have to convert the enum into a string, but if I add TextColumn::make("role") to the table, I expected to get an error saying something like cannot convert enum to string, but I get this instead: App\Models\User::role must return a relationship instance, but "null" was returned. Was the "return" keyword used? Am I missing something essential here? I use pivot values many places like this, but this one was not working. Let me know if you need more data Thank you!
2 replies
FFilament
Created by Joachim Strand on 4/21/2024 in #❓┊help
Custom page color
No description
6 replies
FFilament
Created by Joachim Strand on 4/13/2024 in #❓┊help
Reset custom table header action modal form
Hi, I have a table header action with a form on a modal that works great. I recently wanted to add a "add and create another" submit button to the modal since I found myself saving and adding again alot. This is my table header action button placed in the ->headerActions() of the table. I followed the instructions on how to add button, but how can I reset the form? You can see in the action that I tried many options, but none are working.
Tables\Actions\Action::make("add")
->label("Add Segment")
->icon("heroicon-m-plus")
->modalSubmitActionLabel("Save")
->extraModalFooterActions(fn (Tables\Actions\Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label("Save and add another"),
])
->closeModalByClickingAway(false)
->form(SegmentForm::getForm())
->action(function(array $data, array $arguments, Tables\Actions\Action $action, Forms\Set $set){

// .. The action

if($arguments['another'] ?? false){

// How to reset the form?
// Have tried these combinations
$action->resetFormData();

// Tried with an empty array and with all the fields with "empty" states
$action->formData([
"type" => "" // also tried null
]);
$action->fillForm([
"type" => "" // also tried null
]);

// Also tried $set
$set("type", null);



// Stopping the modal from closing
$action->halt();
}
}),
Tables\Actions\Action::make("add")
->label("Add Segment")
->icon("heroicon-m-plus")
->modalSubmitActionLabel("Save")
->extraModalFooterActions(fn (Tables\Actions\Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label("Save and add another"),
])
->closeModalByClickingAway(false)
->form(SegmentForm::getForm())
->action(function(array $data, array $arguments, Tables\Actions\Action $action, Forms\Set $set){

// .. The action

if($arguments['another'] ?? false){

// How to reset the form?
// Have tried these combinations
$action->resetFormData();

// Tried with an empty array and with all the fields with "empty" states
$action->formData([
"type" => "" // also tried null
]);
$action->fillForm([
"type" => "" // also tried null
]);

// Also tried $set
$set("type", null);



// Stopping the modal from closing
$action->halt();
}
}),
` Anyone experienced this and have solved it? 🙂 Thank you for your help!
4 replies
FFilament
Created by Joachim Strand on 4/11/2024 in #❓┊help
Reset the form and don't close the modal
In the documentation (https://filamentphp.com/docs/3.x/actions/modals#adding-an-extra-modal-action-button-to-the-footer) if I want to add a footer action to a modal that works like the "create and create another", I can create an action and add an argument to check for that, but in that argument it just sais a comment // Reset the form and don't close the modal. How do I do that? how can I prevent the modal from closing? Or atleast have it reopen with a blank form?
5 replies