Ralph Morris
Ralph Morris
FFilament
Created by Ralph Morris on 12/4/2024 in #❓┊help
$container must not be accessed before initialization from within Action
I have the following header Action on an EditOrder resource page.
Actions\Action::make('process_return')
->form(function(Get $get, $record) {
$fields = [];

foreach ($record->items as $orderItem) {
$fields[] = Group::make([
Placeholder::make($orderItem->id.'product_title')
->label('Product')
->content(function() use ($orderItem) {
return $orderItem->product_title . ($orderItem->product_option_title ? ' - ' . $orderItem->product_option_title : '');
}),
TextInput::make($orderItem->id.'.quantity_to_return')
->label('Quantity to return/refund.')
->numeric()
->maxValue($orderItem->quantity)
->suffix('/ ' . $orderItem->quantity)
->live(),
Placeholder::make($orderItem->id.'return_value')
->label('Return value')
->content(function() use ($get, $orderItem) {
return $get($orderItem->id.'.quantity_to_return');
}),
])
->columns(4);
}

return $fields;
})
->action(function (array $data) {
dd($data);
}),
Actions\Action::make('process_return')
->form(function(Get $get, $record) {
$fields = [];

foreach ($record->items as $orderItem) {
$fields[] = Group::make([
Placeholder::make($orderItem->id.'product_title')
->label('Product')
->content(function() use ($orderItem) {
return $orderItem->product_title . ($orderItem->product_option_title ? ' - ' . $orderItem->product_option_title : '');
}),
TextInput::make($orderItem->id.'.quantity_to_return')
->label('Quantity to return/refund.')
->numeric()
->maxValue($orderItem->quantity)
->suffix('/ ' . $orderItem->quantity)
->live(),
Placeholder::make($orderItem->id.'return_value')
->label('Return value')
->content(function() use ($get, $orderItem) {
return $get($orderItem->id.'.quantity_to_return');
}),
])
->columns(4);
}

return $fields;
})
->action(function (array $data) {
dd($data);
}),
I am attempting to use Get $get($orderItem->id.'.quantity_to_return') to retrieve the quantity of items that are being returned so that I can show a preview of the $ amount that will be refunded. However, I am getting "$container must not be accessed before initialization" when attempting to call $get(). Is $get() not possible within a header Action? Any other way I can achieve this? Thanks
4 replies
FFilament
Created by Ralph Morris on 11/25/2024 in #❓┊help
How to output TextEntry on an edit page.
No description
6 replies
FFilament
Created by Ralph Morris on 11/7/2024 in #❓┊help
Price (in pence) field - show result in pounds in suffix/or somewhere else that's sensible
Hi, I am attempting to let a user enter a price in pence, and then show them the converted amount in pounds in a clean and simple way. I hace tried the following but unfortunately the suffix doesn't get updated.
Forms\Components\TextInput::make('price')
->label('Price (in pence)')
->numeric()
->live()
->suffix(function($record) {
return '£'.number_format($record->price / 100, 2);
}),
Forms\Components\TextInput::make('price')
->label('Price (in pence)')
->numeric()
->live()
->suffix(function($record) {
return '£'.number_format($record->price / 100, 2);
}),
Any ideas on how I could achieve someting like this? Thanks!
6 replies
FFilament
Created by Ralph Morris on 4/16/2024 in #❓┊help
TextInputColumn on pivot table inside relation manager
I have a relationship manager on a pivot table, and a Tables\Columns\TextInputColumn::make('note') the note field exists on the pivot table. This is output successfully in the table list. However, when editing the column it tries to save to the related table instead of on the pivot. Is there any way that I can override the save functionality on the TextInputColumn to save on the $model->pivot table? Thanks!
3 replies
FFilament
Created by Ralph Morris on 2/27/2024 in #❓┊help
Uploading file and setting max width/auto height
Hey all, hoping someone can help. I have the following code:
Forms\Components\FileUpload::make('image')
->directory('cms')
->image()
->imageEditor()
->imageEditorAspectRatios([
null,
'16:9',
'9:16',
'4:3',
'3:4',
'1:1',
])
->imageResizeMode('contain')
->imageResizeTargetWidth('1288')
Forms\Components\FileUpload::make('image')
->directory('cms')
->image()
->imageEditor()
->imageEditorAspectRatios([
null,
'16:9',
'9:16',
'4:3',
'3:4',
'1:1',
])
->imageResizeMode('contain')
->imageResizeTargetWidth('1288')
I am trying to upload an image and reduce and images that are too large to max 1288px width, whilst keeping the height dynamic. However, the above code stretches a smaller image to hit 1288px width. How can i stop it stretching the image and only reduce the size if too big? Thanks
1 replies
FFilament
Created by Ralph Morris on 2/27/2024 in #❓┊help
Modify query in Resource if not searching
Hey all, I am trying to only include top level pages on a PageResource by modifying the eloquent query on the PageResource. You can then access child pages via a PageRelationshipManager. However if a user searches, I want to include the child pages in the PageResource search result. My code is below:
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->when(!request('tableSearch'), function($query) {
$query->whereNull('parent_id');
});
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->when(!request('tableSearch'), function($query) {
$query->whereNull('parent_id');
});
}
This works if you refresh the page as request('tableSearch') returns the seaerch query. But if you just search and let livewire do the ajax search, request('tableSearch') returns null. Any ideas? Thanks
6 replies
FFilament
Created by Ralph Morris on 2/24/2024 in #❓┊help
League\Flysystem\UnableToRetrieveMetadata Unable to retrieve the visibility for file at location:
Hey all, hoping someone can help. Filament Version: 3.2 Laravel: 10.43 league/flysystem-aws-s3-v3": "^3.0" I am getting the following error when trying to upload files to S3 through the RichEditor. S3 uploads work fine with a simple FileUpload field, and also using Laravel Media Library file upload field, but during upload inside an editor I am getting this error: League\Flysystem\UnableToRetrieveMetadata Unable to retrieve the visibility for file at location: My code:
Forms\Components\RichEditor::make('content')
->fileAttachmentsDisk('s3')
->fileAttachmentsDirectory('attachments')
->fileAttachmentsVisibility('public')
Forms\Components\RichEditor::make('content')
->fileAttachmentsDisk('s3')
->fileAttachmentsDirectory('attachments')
->fileAttachmentsVisibility('public')
I tracked the error to line 120 of the HasFileAttachments trait which is inside a method name handleUploadedAttachmentUrlRetrieval(). Line 120: if ($storage->getVisibility($file) === 'private') { The getVisibility method is throwing the error. However, the file is successfully uploaded to S3 and $file is pointed at the correct location: example: attachments/QB4Gc4ioPAaBnvPkYIeGVjqBT7LQakY0qAqVL1cB.jpg When commenting out the if statement on line 120 to test, the image does render in the editor but I have no idea why it can't read the visibility. Any help appreciated! Thanks Ralph
20 replies