barrerakj
Disable "Create" button in a form, in the create view
Very simple. I go to the form that creates an Order resource. For every order, you need to select a client. Once you select a client, I can get all the info of the client. In my app, if the client is not enabled, the order should not have the option to be created. How do I disable the "Create" and "Create and create another" buttons at the bottom based on a condition?
1 replies
Same exact code on different Fields
Hey, easy question here. I have 3 different fields that have the same exact code in the ->afterStateUpdated(). I always try to follow good practices and not to repeat code, but I'm not sure how to do this. This is how it looks
->afterStateUpdated(function (callable $set, $get) {
$quantity = $get('quantity') == '' ? 1 : $get('quantity');
$width = $get('width') == '' ? 1 : $get('width');
$height = $get('height') == '' ? 1 : $get('height');
if($get('height') == '' or $get('width') == ''){
$set('totalm', 0);
} else {
$set('totalm', bcdiv(((($width * $height) * $quantity)),1,2) );
}
})
And it's exactly the same in 3 different fields. It actually doesn't matter what's inside or the logic around it, I just want to ask if I can write the code just once somewhere and use it where I want. I'm actually not sure because of the $set and $get callables.
5 replies
Get info of the selected record in AttachAction
I have a very simple AttachAction in a RelationManager. The user selects whatever option they want, using this
$action->getRecordSelect(),
In that very moment, from that selection, I need to populate a couple fields below.
I know how to get the ownerRecord, I now how to get the data that will be saved, and those are not my questions. I need whatever information I can from that selection. Any ideas?23 replies
How do I change the modal text of a custom Action?
I have a simple custom Action and I'm using
->requiresConfirmation()
. All that I want is to change the heading, subheading and button label. I already checked this part of the documentation https://filamentphp.com/docs/2.x/admin/pages/actions#setting-a-modal-heading-subheading-and-button-label and added this
->modalHeading('Delete posts')
->modalSubheading('Are you sure you'd like to delete these posts? This cannot be undone.')
->modalButton('Yes, delete them')
Which is the example on the docs, but nothing changes. I already clear the cache on the laravel app, but nothing. Is there something else that I need to do?5 replies
Access recently created record on CreateAction
Ok, so I'm creating records in a modal action. I wan to run something after the fields are saved to the database, so I'm using something like this
->after(function () {
// Runs after the form fields are saved to the database.
})
Question. In other actions, you can use $this->record
to access the current record. However, in this action, this object doesn't exists. How do I access the record that was just created?2 replies
How to get the current relationship entry on a RelationManager action?
My goal is to get the current relationship information, let me explain. Let's say that I have an Order model, a Product model and a many to many relationship between them using BelongsToMany in both models. I'm using a relation manager to attach products to an order.
For example, If I use this on an AttachAction
->after(function (RelationManager $livewire) {
dd($livewire->mountedTableActionData['recordId'];
$livewire->emit('refresh');
})
That "recordId" is the id of the product that was attached via the relationship. However, is there a way to access the pivot table information? Let's say I have a pivot table named "order_products", every time I "attach" a product to an order, there's a new entry on that table.
Is there like an event that is emitted as described in the Form Builder documentation? Or maybe in the livewire object that I use in the callback? Where do I found that recently created row in the pivot table?21 replies
Configure Spatie Media Library plugin to upload to Digital Ocean
Ok, I installed the plugin, all good. Then, I created a DO Spaces bucket, add the CORS config, then in Laravel installed the required packages, added the disk with the name 'digitalocean', and it worked good. When I do a simple
Storage::put('file.txt', 'Contents of the file');
in Tinker to test, it actually creates a file in DO Spaces. All good here.
However, when I use the field, and try to add images, those images are saved correctly, except that they go to the public disk. I already change the FILESYSTEM_DISK variable in .env to 'digitalocean' and already change the config in filesystems.php like this
'default' => env('FILESYSTEM_DISK', 'digitalocean'),
I also made sure to publish the media-library.php config, and change the disk_name to this
'disk_name' => 'digitalocean',
Actually, the livewire part of the field performs a temporary file upload, and if I specify the 'digitalocean' disk in the livewire.php config file, it actually works.
So, when I save the file, why is Media Library still sending the files to the public disk? Is there any other config that I need to change?5 replies
How to show thumbnails on SpatieMediaLibraryFileUpload field?
Everything is working fine. I installed Spatie Media Library, imported the field, and I'm currently using it. I have it set up for multiple images.
SpatieMediaLibraryFileUpload::make('Imagenes')
->columnSpan('full')
->multiple()
->conversion('thumb')
->enableReordering(),
However, when I see the resource, it does show the the images, but it shows them as a list, and not the thumbnails. How can I do that? I understand SpatieMediaLibraryFileUpload is for uploads, but is there an other field to actually show images? Or can I use SpatieMediaLibraryFileUpload to display the images in some way?
4 replies
How do I use a Toogle to hide/show an Input?
So I have a toogle component and an input component, pretty straight forward. I want to show or hide the input base on the toogle state
Toggle::make('Agregar bordado?')->inline(),
TextInput::make('embroidery')
->label("Texto de bordado"),
I thought on add reactive(), save the boolean state of the toogle, and check on the input that boolean value but that seems extremely complicated for a single action. Is there any way to do this without saving the value?3 replies