Marcellin
Marcellin
FFilament
Created by Marcellin on 3/20/2024 in #❓┊help
How to retrieve id from url and insert as default value in TextInput?
Inside a form in a resource page, i need to retrieve the record id (in this case 1) from the following url: /admin/products/1/create-variant, and set it as default value inside a text input. request()->route()->parameter('record') returns null when included in the default value. I am using the following code: ``` public static function form(Form $form): Form { return $form ->schema([ Forms\Components\TextInput::make('product_id') ->default( // What to insert here? ) ->required(), ]) }
6 replies
FFilament
Created by Marcellin on 11/2/2023 in #❓┊help
How to Make Multiple Select Filters Combine with 'And' Logic Instead of 'Or' Logic in FilamentPHP?
When I select multiple options from a single Select Filter, it treats them as an orWhere, which is expected. However, when I select options simultaneously from two or more Select Filters, it also treats them as orWhere. However, I need them to be treated as andWhere. How can I achieve this behavior? Here are two examples of the filters:
SelectFilter::make('type_id')
->label('Type')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];
foreach ($values as $value) {
$query = $query->orWhere('types.type_id', $value);
}
return $query;
})
->options(Type::all()->pluck('type_name', 'type_id'))
->multiple(),
SelectFilter::make('category_id')
->label('Category')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];

foreach ($values as $value) {
$query->orWhere('categories.category_id', $value);
}

return $query;
})
->options(Category::all()->pluck('category_name', 'category_id'))
->multiple();
SelectFilter::make('type_id')
->label('Type')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];
foreach ($values as $value) {
$query = $query->orWhere('types.type_id', $value);
}
return $query;
})
->options(Type::all()->pluck('type_name', 'type_id'))
->multiple(),
SelectFilter::make('category_id')
->label('Category')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];

foreach ($values as $value) {
$query->orWhere('categories.category_id', $value);
}

return $query;
})
->options(Category::all()->pluck('category_name', 'category_id'))
->multiple();
5 replies
FFilament
Created by Marcellin on 10/31/2023 in #❓┊help
Generate unique time() filenames for file uploads inside Repeater
Im trying to generate filenames based on the time() method using getUploadedFileNameForStorageUsing inside a repeater. The problem is that all files are generated using the same time value and are overriden by the last file. This is the component (i dont want to include the original file name):
Forms\Components\Repeater::make('tour_locations')
->schema([
FileUpload::make('image_path')
->disk('s3')
->directory('images')
->visibility('public')
->label('Image')
->image()
->maxSize(256)
->required()
->getUploadedFileNameForStorageUsing(
fn (TemporaryUploadedFile $file): string => time() . "." . $file->getClientOriginalExtension()
),
])
Forms\Components\Repeater::make('tour_locations')
->schema([
FileUpload::make('image_path')
->disk('s3')
->directory('images')
->visibility('public')
->label('Image')
->image()
->maxSize(256)
->required()
->getUploadedFileNameForStorageUsing(
fn (TemporaryUploadedFile $file): string => time() . "." . $file->getClientOriginalExtension()
),
])
3 replies
FFilament
Created by Marcellin on 10/1/2023 in #❓┊help
How to Make Multiple Select Filters Combine with 'And' Logic Instead of 'Or' Logic?
When I select multiple options from a single Select Filter, it treats them as an orWhere, which is expected. However, when I select options simultaneously from two or more Select Filters, it also treats them as orWhere. However, I need them to be treated as andWhere. How can I achieve this behavior? Here are two examples of the filters:
SelectFilter::make('shipper_id')
->label('Shipper')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];
foreach ($values as $value) {
$query = $query->orWhere('shippers.shipper_id', $value);
}
return $query;
})
->options(Shipper::all()->pluck('shipper_name', 'shipper_id'))
->multiple(),
SelectFilter::make('shipper_id')
->label('Shipper')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];
foreach ($values as $value) {
$query = $query->orWhere('shippers.shipper_id', $value);
}
return $query;
})
->options(Shipper::all()->pluck('shipper_name', 'shipper_id'))
->multiple(),
SelectFilter::make('clearance_agent_id')
->label('Clearance Agent')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];

foreach ($values as $value) {
$query->orWhere('clearance_agents.clearance_agent_id', $value);
}

return $query;
})
->options(ClearanceAgent::all()->pluck('clearance_agent_name', 'clearance_agent_id'))
->multiple();
SelectFilter::make('clearance_agent_id')
->label('Clearance Agent')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];

foreach ($values as $value) {
$query->orWhere('clearance_agents.clearance_agent_id', $value);
}

return $query;
})
->options(ClearanceAgent::all()->pluck('clearance_agent_name', 'clearance_agent_id'))
->multiple();
1 replies
FFilament
Created by Marcellin on 9/1/2023 in #❓┊help
Add create another and cancel buttons in custom form
I created a custom form but I need to know how can i include the create another and cancel buttons in the page, with their respective styling.
<x-filament::page>
<form wire:submit.prevent="submit">
{{ $this->form }}
<div class="mt-4">
<x-filament::button type="submit">
Create
</x-filament::button>
</div>
</form>
</x-filament::page>
<x-filament::page>
<form wire:submit.prevent="submit">
{{ $this->form }}
<div class="mt-4">
<x-filament::button type="submit">
Create
</x-filament::button>
</div>
</form>
</x-filament::page>
I currently only know the create button process.
5 replies
FFilament
Created by Marcellin on 7/24/2023 in #❓┊help
Custom Form Handling
Inside my custom form page, how can i redirect the user back after form submit and where to store the code to send a notification? I have followed the following docs https://filamentphp.com/docs/2.x/forms/getting-started#preparing-your-livewire-component but Im having a hard time handling what happens after form submit (redirect, send error notification...).
2 replies
FFilament
Created by Marcellin on 7/23/2023 in #❓┊help
Retrieve Records from getTableQuery in a Custom Resource for Dynamic Table Data Display
How can I retrieve the record ID inside the getTableQuery method in a custom resource so that I can dynamically display table data based on this record? Specifically, I have the following custom action:
Tables\Actions\EditAction::make()
->url(fn (Container $record): string => ContainerResource::getUrl('listOrders', ['record' => $record]))
Tables\Actions\EditAction::make()
->url(fn (Container $record): string => ContainerResource::getUrl('listOrders', ['record' => $record]))
And I want to use the retrieved record ID in the where clause of the getTableQuery as shown below:
$query = Order::join('containers', 'orders.container_id', '=', 'containers.container_id')
->where('orders.container_id', /* I need to insert the record ID here, but how can I get it? */);
$query = Order::join('containers', 'orders.container_id', '=', 'containers.container_id')
->where('orders.container_id', /* I need to insert the record ID here, but how can I get it? */);
Note: The custom resource is for a system that manages orders and containers, and I want to list orders for a specific container based on the record ID retrieved from the URL when editing a container.
7 replies