rg.block
Saving repeater with relationship as json
Is it possible to save a repeater's data as json when the repeater has a relationship?
To better explain, I am working within the panel builder. I have 2 main models, Order and Document. Order hasMany documents and Document belongsTo Order.
Inside my OrderResource file: If I go ahead and setup a repeater named ('form_data') with no relationship, and then I set my orders table properly with a json data type column and my model with the proper casts, the data gets saved correctly into the form_data column as a json object. But then if I make a change to the repeater and add ->relationship('documents'), keep the same name for the repeater ('form_data'), then when I try to save the data it tries to save the data in individual columns based on the names of the fields inside the repeater as opposed to saving them inside the column 'form_data' under my documents table.
I have looked at the filament demo along with multiple videos on laracasts, codecourse, youtube, and I am yet to find an example of someone saving a repeater's data with a relationship inside a json column. So perhaps I am just trying to do something that is not actually supported.
Happy to paste any code if this is something that is supported.
10 replies
Unable to get notification broadcasted to pusher
First let me start by listing what I have done and tried. I have pretty much everything working with the exception of the event being sent to pusher, and I have looked here and on discord and while there are a few questions related to this, most are just dead since the OP never replied back.
-Pusher configuration is setup and correct
-Echo is setup
-Pusher SDK is installed
Upon saving a form, I am using this to dispatch the event:
DatabaseNotificationsSent::dispatch($recipient);
I also tried this first per the docs, but they should be equivalent event(new DatabaseNotificationsSent($recipient));
I can see in my logs that the event fires up, and on the pusher dashboard I can see 3 events:
1.Connection
2.Subscribed
3.Occupied
But I am not able to see the actual event.
My config/filament.php file has the code below which I had it commented it out until my last 2 tries because I was initializing echo inside a custom js file that I am loading in my app layout file:
'broadcasting' => [
'echo' => [
'broadcaster' => 'pusher',
'key' => env('VITE_PUSHER_APP_KEY'),
'cluster' => env('VITE_PUSHER_APP_CLUSTER'),
'forceTLS' => true,
],
],
My custom js file has this:
import Echo from 'laravel-echo';
import Pusher from 'pusher-js';
window.Pusher = Pusher;
window.Echo = new Echo({
broadcaster: 'pusher',
key: import.meta.env.VITE_PUSHER_APP_KEY,
cluster: import.meta.env.VITE_PUSHER_CLUSTER,
forceTLS: true
});
const userId = window.userId;
window.Echo.private(
App.Models.User.${userId})
.listen('.database-notifications.sent', (e) => {
console.log("Event received:", e);
});
Anyone has been able to successfully get the database notifications to work with pusher? I have them working with the default polling but cant get it to work with Echo/Websockets.8 replies
Required fields validation on submit inside modal
Hello, I have a table inside a full page livewire component. The table has some actions that open up a couple modals, and inside the modal I have a a form with several fields marked as required. Is there anything specific that needs to be done to make sure those fields are filled out other than marking them as
->required
? I am asking because they do not get validated when I submit the modal form, so I could either be missing something or something else is going on. They do get marked with the red asterisks but that is it, no validation on submission.
I have read the sections about Actions, advanced forms, validation, and probably anything else I can think of, and nothing is specifically mentioned, which leads me to believe ->required
is all that is needed.2 replies
->extraAttribute not working on TextInput
I have this TextInput on a form inside an app I just upgraded to v3.
TextInput::make('status')
->label('Status')
->extraAttributes(['class' => 'text-teal-600'])
->disabled(),
That exact code used to work on v2, but on V3 the text color does not change. I also tried ->extraInputAttribute but no luck. Is there something odd that I need to look for? The TextInput is inside Grid\Section.67 replies
Full page table component showing spinners non-stop
Has anyone experienced an issue when using a table as a full page livewire component and having things like actions or searchable items just display the loading (spinner) icon non-stop? I upgraded my app from v2 to v3 and I just started seeing this. I recreated the page from scratch and the issue is still there. Could I be loading something incorrectly? I get through the docs section by section, and field by field but I can't find the issue. Everything works fine on v2.
I am attaching a video.
4 replies
FileUpload on edit page
I have a standalone table with actions. One of the actions is Edit which takes me to the edit page where I have a standalone form. There I have some Placeholders and Text Inputs, which all load the information about my package just fine. I then have a TableRepeater with a TextInput and a FileUpload. The Repeater is designed to hold information about documents that belong to the package. I can display the information regarding the document name on the TextInput fine. Still, I have not been able to have the FileUpload get 'loaded' with the image belonging to the document. I have verified all of the recommendations mentioned in the documentation and on some posts here, such as the correct URL, CORS, and path. When creating the record on the 'Create' page, I should mention that the images are saved to S3 with no issues. The issue is on the edit page, which displays no console errors.
Inside my mount method I am doing this:
$this->documents = $package->documents->map(function ($document) {
return [
'document_name' => $this->package->provider === 1
? $document->documentSet1->name
: $document->documentSet2->name,
'file_name' => $document->image->file_name,
];
})->toArray();
$this->form->fill([
'package_name' => $this->package->name,
'created_at' => $this->package->created_at,
'updated_at' => $this->package->updated_at,
'documents' => $this->documents,
]);
and the code for the repeater/FileUpload is this:
Section::make('Document Details')
->schema([
TableRepeater::make('documents')
->columnWidths([
'document_name' => '50%',
])
->schema([
TextInput::make('document_name')
->string()
->label('Document Name')
->disabled(),
FileUpload::make('file_name')
->acceptedFileTypes(['application/pdf', 'image/tiff'])
->disk('s3')
->directory('submitted'),
])
->disableItemMovement()
->disableLabel()
->hideLabels()
->columnSpan(2)
->disableItemCreation()
->disableItemDeletion(),
])
->compact()
->columnSpan(2),
I read a post here about Filament creating a temp URL when using S3, so I am not sure if the issue could be me missing something. Someone else also asked about loading the image on the edit page, but I think it was unanswered.
I have also looked at the demo code, but I do not see anything specific that could be missing.
Lastly, I should add that if I dd($$this->documents) I get something like this which shows the correct image path for each document.
array:2 [▼ // app/Http/Livewire/PackagesEdit.php:41
0 => array:2 [▼
"document_name" => "TestName1"
"file_name" => "submitted/TestName1Image.pdf"
]
1 => array:2 [▼
"document_name" => "TestName2"
"file_name" => "submitted/TestName2Image.pdf"
]
]
35 replies
Placeholder content based on conditional logic based on value from another component?
Is it possible to set the content of a Placeholder with conditional logic if the value of another component or even the value of a property I am using on a ->mountUsing is equal to something?
In more detail, I have a table and I am using Action to open a modal window. The modal has a few TextInputs whose values are being set with ->mountUsing, and then I have a Repeater using ->relationship(), and the repeater has a Placeholder and other components inside. I would like the content of the Placeholder to be something if the value of one of the mounted TextInputs is 1, something else if it is 2, and so on.
The code for my Action is:
Action::make('viewPackage')
->label('View')
->mountUsing(fn (Forms\ComponentContainer $form, Package $record) => $form->fill([
'package_name' => $record->name,
'number_of_documents' => $record->number_of_documents,
'state_name' => $record->jurisdiction->state->name,
'jurisdiction_name' => $record->jurisdiction->name,
'provider' => $record->provider_id,
]))
->icon('heroicon-s-eye')
->color('success')
->visible(fn ($record) => $record->status_id === 3)
->action(function (Package $record, array $data): void {
$record->package()->associate($data['packageId']);
$record->save();
})
Where 'provider' => $record->provider_id, is the value I need to be used on the Placeholder logic.
Right now my Placeholder code is just setting the value like:
Placeholder::make('document_type_name')->content(fn ($record) => $record?->documentTypePrimary->name),
which works when the provider is 1, but I am not evaluating that, so I would like to check for whatever value the provider is and then set $record?->documentTypePrimary to be ->documentTypeSecondary, ->documentTypeTernary, etc.
Is that something that can be done here, or perhaps I am just overcomplicating things here? I have tried using a function but I just cant find a way to access the value of provider
I am adding the gist to the entire action code here for full reference.
https://gist.github.com/rgut13rrez/e18fc9aafb72e26e7c156ea2c42653db4 replies
Display relationship on table column
I currently have a table with 2 of its columns displaying the name of a city and its state respectively. I would like to be able to combine them into one column, but I have tried several approaches and neither one works as I just get no data on the combined column.
I currently have it in two columns like this:
protected function getTableColumns(): array
{
return [
TextColumn::make('name')->searchable(),
TextColumn::make('created_at')
->label('Date')
->date()
->sortable(),
TextColumn::make('city.name')
->label('City')
->sortable(),
TextColumn::make('city.state.name')
->label('State')
->sortable(),
];
}
The option I tried that to me appeared to be close was using formatStateUsing like this:
TextColumn::make('City, State')
->formatStateUsing(function (Package $package) {
if ($package->city && $package->city->state) {
return "{$package->city->name}, {$package->city->state->name}";
}
return '';
}),
But that still did not work. I think I am doing something wrong or maybe missing something.
That is assuming it is possible to display what I need in one column.
Does anyone have a suggestion/fix that can accomplish displaying the city and state under the same column?10 replies
Fill repeater in custom form in modal
Hello, to begin with, this is a semi long question/issue, and I honestly was not feeling good about posting it and possibly have someone willing to help read through the whole thing. So I think that the fair thing to do would be to buy someone coffee/beer/your drink of choice or sponsor them if available.
I am working with a table using actions, and when clicking on the action, it opens up a modal which has a custom form in it. The form has some text inputs which I am filling in and showing them as disabled. So far so good here. Then I am using a table-repeater and I am trying to pre-fill it as well. Here is where the issues start for me. The table rows need to show data from a relationship. My models are Package and Document where Package has a hasMany with Document and Document has a belongsTo with Package. All the data related to Package is fine but I have not been able to fill the table-repeater with as many rows as the package has documents, and fill the document_type_id TextInput. Finally, on the more complicated part (for me), retrieve the image from s3 (image name is on a column on the Documents table ).
Here is my gist of what the code looks like right now:
https://gist.github.com/rgut13rrez/2275aec31e0d5120cf6da4fbfab378fe
21 replies
BadgeColumn -> colors not displaying properly
Hello, I have a standalone table that I am having issues with when trying to set the badge color to be set by the value of it. The odd part is that I am using enum to transform the set of know values and that works as expected. At first I thought that had something to do with it, but even if I remove the enum it is not working. I should add that the color that shows on all the cells for the column is gray.
function getTableColumns(): array has:
BadgeColumn::make('status_id')
->label('Status')
->colors([
'danger' => '1',
'warning' => '2',
'success' => '3',
])
->enum([
'1' => 'Recorded',
'2' => 'Rejected',
'3' => 'Submitted',
]),
tailwind.config.js has:
theme: {
extend: {
colors: {
danger: colors.rose,
primary: colors.blue,
success: colors.green,
warning: colors.yellow,
},...
4 replies
Is it possible to dynamically set ->defaultItems to be the value from another field?
I am toying with this, but I am not even sure if it is valid.
->defaultItems(fn (Closure $get) => $get('../../number_of_documents') != null)
Where number_of_documents is a text input of type number outside the repeater9 replies