Dimitar Papazov DEV
Dimitar Papazov DEV
FFilament
Created by Dimitar Papazov DEV on 10/15/2024 in #❓┊help
Change language Only in Admin panel
Hello, How to change the language only while we are in the /admin? I need my main app to be in EN, so in my .env APP_LOCALE=en, but is there something to add to change the lang only for admin? Is there a workarount with some hook?
2 replies
FFilament
Created by Dimitar Papazov DEV on 10/9/2024 in #❓┊help
Action->form() not getting filled when reusing form
Hello, Having a Action on a view page. I want to reuse the form from InvoiceResource as i did, but i want to force fill it with data from the $record, but it doesnt get filled. No errors, just doesnt work; Any ideas on how to handle this?
<?php

namespace App\Filament\Resources\OrderResource\Pages;

use App\Filament\Resources\InvoiceResource;
use App\Filament\Resources\OrderResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;

class ViewOrder extends ViewRecord
{
protected static string $resource = OrderResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ActionGroup::make([
Actions\Action::make('generateInvoice')
->icon('heroicon-o-clipboard-document-list')
->form(fn($record, $form) => InvoiceResource::form($form))
->formData([
'order_id' => $this->record->id,
'receiver_name' => $this->record->names,
'receiver_phone' => $this->record->phone,
'receiver_email' => $this->record->email,
'total' => $this->record->total,
])
->color('gray'),

]) ->button()->color('gray') ->label('Invoice'),
];
}
}
<?php

namespace App\Filament\Resources\OrderResource\Pages;

use App\Filament\Resources\InvoiceResource;
use App\Filament\Resources\OrderResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;

class ViewOrder extends ViewRecord
{
protected static string $resource = OrderResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ActionGroup::make([
Actions\Action::make('generateInvoice')
->icon('heroicon-o-clipboard-document-list')
->form(fn($record, $form) => InvoiceResource::form($form))
->formData([
'order_id' => $this->record->id,
'receiver_name' => $this->record->names,
'receiver_phone' => $this->record->phone,
'receiver_email' => $this->record->email,
'total' => $this->record->total,
])
->color('gray'),

]) ->button()->color('gray') ->label('Invoice'),
];
}
}
5 replies
FFilament
Created by Dimitar Papazov DEV on 7/8/2024 in #❓┊help
Modify query on AttachAction
Hello, I have this code, allowing to attach more products with BelongsToMany Relation:
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->form(fn(Tables\Actions\AttachAction $action): array => [
$action->getRecordSelect()->required(),
Forms\Components\ColorPicker::make('color')
->required()
])
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->form(fn(Tables\Actions\AttachAction $action): array => [
$action->getRecordSelect()->required(),
Forms\Components\ColorPicker::make('color')
->required()
])
It works, but I want to modify the query when saving, to add the inverse record in the DB, how do your do that ? Tried $action->getRecordSelect()->saveRelationshipsUsing, but since it doesnt have ->relationship chained it doesnt work. Is there any way to do this, event if its not trough filament? Thanks!
3 replies
FFilament
Created by Dimitar Papazov DEV on 5/22/2024 in #❓┊help
Help, Setting runtime config only for one FileUpload
Hi firends, Here I have a FileUpload that is setupped to work with S3 pre-signed links and I need to change the livewire's temp dir disk to be one. So my idea is to have FileUpload component extended and set the config runtime value there:
Class S3FileUpload Extends FileUpload
{
protected function setUp(): void
{
parent::setUp();
config(['livewire.temporary_file_upload.disk' => 's3']);
}

}
Class S3FileUpload Extends FileUpload
{
protected function setUp(): void
{
parent::setUp();
config(['livewire.temporary_file_upload.disk' => 's3']);
}

}
but how to get it back to the default after components finished rendering/executing so no conflict or overide will happen if I have 1 S3FileUpload field and next to it i have a regular FileUpload? Any idea how to handle this?
6 replies
FFilament
Created by Dimitar Papazov DEV on 5/20/2024 in #❓┊help
Chunk upload to Filament's FileUpload?
Hi, is there a plan to make the built in FileUpload to handle chunk file uploads or is there a working component that does that, its very hard to implement manualy.
1 replies
FFilament
Created by Dimitar Papazov DEV on 3/5/2024 in #❓┊help
Multiple file upload grid Reorderable not working
Hey, guys, this code, and it uploads images fine, but when I try to reorder them, its not even working. How do you solve this? How to reorder already uploaded files?
FileUpload::make('images')
->multiple()
->saveRelationshipsUsing(function ($record, $state) { ... })
// here, nothing gets evaluated.
->reorderUploadedFilesUsing(function ($state) { dd($state); })
FileUpload::make('images')
->multiple()
->saveRelationshipsUsing(function ($record, $state) { ... })
// here, nothing gets evaluated.
->reorderUploadedFilesUsing(function ($state) { dd($state); })
2 replies
FFilament
Created by Dimitar Papazov DEV on 2/11/2024 in #❓┊help
Multiple FIleUpload Reorderable
Hey friends, I have little question on how things work. I have a FileUpload, multiple + reorderable, used a **saveRelationshipsUsing** to hook in to the saving part, but when I try to reorder them with **reorderUploadedFilesUsing**, it seems that its tries to go through this method (saveRelationshipsUsing) again after reorder and it removes the uploaded files from the filepond component visualy (after save), but after refresh they are still there. Also they don't appear to be sorted properly. How to prevent the files to disapear and how to force the images to come sorted, since the sortBy is not honored? How can I approach this? Here is my code:
FileUpload::make('images')
->multiple()
->label('Снимки')
->reorderable()
->minFiles(1)
->disk('uploads')
->directory('products')
->panelLayout('grid')
->saveRelationshipsUsing(function ($record, $state) {
$pos = intval($record->images()->count());
if(!is_null($state)){
foreach ($state as $path) {
$file = File::firstOrCreate([
'name' => basename($path),
'path' => $path,
'disk' => 'uploads',
]);
$record->images()->syncWithoutDetaching($file, [
'order' => $pos + 100,
'group' => 'images',
]);
}
}


})
->reorderUploadedFilesUsing(function ($record, $state) {
if ($state) {
foreach ($state as $pos => $path) {
$record->images()->where('path', $path)->update(['order' => $pos + 100]);
}
}
})
->deleteUploadedFileUsing(function ($record, $file) {
$file = $record->images()->where('path', $file)->first();
$record->images()->detach($file);
Storage::disk('uploads')->delete($file);
$file->delete();
})
->formatStateUsing(function ($record) {
return $record->images->sortBy('order')->pluck('path');
}),
FileUpload::make('images')
->multiple()
->label('Снимки')
->reorderable()
->minFiles(1)
->disk('uploads')
->directory('products')
->panelLayout('grid')
->saveRelationshipsUsing(function ($record, $state) {
$pos = intval($record->images()->count());
if(!is_null($state)){
foreach ($state as $path) {
$file = File::firstOrCreate([
'name' => basename($path),
'path' => $path,
'disk' => 'uploads',
]);
$record->images()->syncWithoutDetaching($file, [
'order' => $pos + 100,
'group' => 'images',
]);
}
}


})
->reorderUploadedFilesUsing(function ($record, $state) {
if ($state) {
foreach ($state as $pos => $path) {
$record->images()->where('path', $path)->update(['order' => $pos + 100]);
}
}
})
->deleteUploadedFileUsing(function ($record, $file) {
$file = $record->images()->where('path', $file)->first();
$record->images()->detach($file);
Storage::disk('uploads')->delete($file);
$file->delete();
})
->formatStateUsing(function ($record) {
return $record->images->sortBy('order')->pluck('path');
}),
6 replies
FFilament
Created by Dimitar Papazov DEV on 5/29/2023 in #❓┊help
Repeater custom input names based on if it is relationship or currently added
Hello, I have a FormBuilder/Repeater with some fields in it with custom name attributes to be able to be submited with the page. I set the input name with ->extraInputAttributes(['name' => 'promotions[promo_from]']). How can I check if current Repeater iteration its comming from existing relation(is existing record) and to change the input name to use the relation id as key as follows: Repeater (relation: promotions)
{datepicker} {datepicker} { input:promotions[1213][regular_price] } { input:promotions[1213][promo_price] } (already created and comming from DB relation)
{datepicker} {datepicker} { input:promotions[1213][regular_price] } { input:promotions[1213][promo_price] } (already created and comming from DB relation)
.. then on click of the repeater "add new" button, the keys of the names to be sequential
{datepicker} {datepicker} { promotions[0][regular_price] } { promotions[0][promo_price] }
{datepicker} {datepicker} { promotions[1][regular_price] } { promotions[1][promo_price] }
{datepicker} {datepicker} { promotions[0][regular_price] } { promotions[0][promo_price] }
{datepicker} {datepicker} { promotions[1][regular_price] } { promotions[1][promo_price] }
Currently I have the following schema for a filament form
<?php
return [
Repeater::make('promotions')
->model($this->product)
->relationship('promotions')
->schema([
DateTimePicker::make('promo_from')
->extraAlpineAttributes([
'name' => 'promotions[promo_from]',
]),

DateTimePicker::make('promo_to')
->extraAlpineAttributes([
'name' => 'promotions[promo_to]',
]),

TextInput::make('price')->extraInputAttributes([
'name' => 'promotions[promo_from]'
]),

TextInput::make('promo_price')->extraInputAttributes([
'name' => 'promotions[promo_from]'
]),
])
];
<?php
return [
Repeater::make('promotions')
->model($this->product)
->relationship('promotions')
->schema([
DateTimePicker::make('promo_from')
->extraAlpineAttributes([
'name' => 'promotions[promo_from]',
]),

DateTimePicker::make('promo_to')
->extraAlpineAttributes([
'name' => 'promotions[promo_to]',
]),

TextInput::make('price')->extraInputAttributes([
'name' => 'promotions[promo_from]'
]),

TextInput::make('promo_price')->extraInputAttributes([
'name' => 'promotions[promo_from]'
]),
])
];
10 replies
FFilament
Created by Dimitar Papazov DEV on 5/12/2023 in #❓┊help
How to set inputs "[name]" attribute to bahave like regular input field
Hi, I'm new to filament form builder, but I have search for this a lot, and didnt found anything. I want to use Filament FormBulder on parts of my page, but the problem is that the Components dont have name attributes and I cant do a global submit of both livewire components and normal blade components in my page. Is there a easy way (and how to do it) of setting the name attribute to each form(livewire) component to act like a normal blade/html component and when you hit a global save button to have the livewire's values available in the request global. Example with given form and what I expect to happen with mixed livewire/filament component and regular inputs:
<form action="">
<h5 class="text-lg mb-2 text-gray-400">Title</h5>
<div class="card mb-8">
@include('admin.partials.form-input', [
'type' => 'text',
'name' => 'title',
'label' => 'Title',
'value' => old('title', $item->text->title),
])
</div>
<h5 class="text-lg mb-2 text-gray-400">PROMOTIONS</h5>
<div class="mb-8">
{{--
(filament livewire component formBuilder)
it renders multiple inputs, but without NAME attributes
--}}
@if ($item->exists)
@livewire('admin.products.promotions-panel', ['product' => $item], key($item->id))
@endif
</div>
<button type="submit">SUBMIT</button>
</form>
<form action="">
<h5 class="text-lg mb-2 text-gray-400">Title</h5>
<div class="card mb-8">
@include('admin.partials.form-input', [
'type' => 'text',
'name' => 'title',
'label' => 'Title',
'value' => old('title', $item->text->title),
])
</div>
<h5 class="text-lg mb-2 text-gray-400">PROMOTIONS</h5>
<div class="mb-8">
{{--
(filament livewire component formBuilder)
it renders multiple inputs, but without NAME attributes
--}}
@if ($item->exists)
@livewire('admin.products.promotions-panel', ['product' => $item], key($item->id))
@endif
</div>
<button type="submit">SUBMIT</button>
</form>
Class ProductsController {
public function update(Request $request, Product $product)
{
dd($request->all());
// Doesnt include the livewire component inputs, bucause they dont have NAME attributes
}
}
Class ProductsController {
public function update(Request $request, Product $product)
{
dd($request->all());
// Doesnt include the livewire component inputs, bucause they dont have NAME attributes
}
}
15 replies