Pasteko
Pasteko
FFilament
Created by Pasteko on 10/23/2023 in #❓┊help
Select dependant from TextInput
Hello, I'm trying to build a zipcode search inside a form.
TextInput::make('zip_code'),
Select::make('city_id')
->relationship('city', 'name')
->required()
->native(false),
TextInput::make('zip_code'),
Select::make('city_id')
->relationship('city', 'name')
->required()
->native(false),
The user enters the zipcode manually in the text field then the select updates with only the corresponding cities. Tried to follow the various examples for dependant selects but maybe there's a better way with v3?
16 replies
FFilament
Created by Pasteko on 10/13/2023 in #❓┊help
Shared hosting deployment
Hello, I have a problem to deploy my filament app to a shared hosting. With Filament v2 I was forced to publish the livewire config and set : 'asset_url' => '' In livewire 3 asset_url is replaced by :
Livewire::setScriptRoute(function ($handle) {
return Route::get('/custom/livewire/livewire.js', $handle);
});
Livewire::setScriptRoute(function ($handle) {
return Route::get('/custom/livewire/livewire.js', $handle);
});
But I don't know where (file) I need to add this?
5 replies
FFilament
Created by Pasteko on 10/10/2023 in #❓┊help
->modifyQueryUsing with relations
Hello, I need to use a 'details' relation to query the state, how can I do this? Tried to add ->with('details') or -details(), please help. $query->with('details')->where('state', 1)) $query->details()->where('state', 1)) Thanks
public function getTabs(): array
{
return [
'enabled' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('state', 1)),
'all' => Tab::make(),
'disabled' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('state', 0)),
];
}
public function getTabs(): array
{
return [
'enabled' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('state', 1)),
'all' => Tab::make(),
'disabled' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('state', 0)),
];
}
5 replies
FFilament
Created by Pasteko on 8/29/2023 in #❓┊help
Form Toggle relationship
No description
11 replies
FFilament
Created by Pasteko on 8/16/2023 in #❓┊help
Enum with form->select
Why is it working for table->TextColumn but not for form->select?
<?php

namespace App\Enums;
use Filament\Support\Contracts\HasLabel;

enum TitreEnum: int implements HasLabel
{
case M = 0;
case MME = 1;

public function getLabel(): ?string
{
return match ($this) {
self::M => 'M.',
self::MME => 'Mme',
};
}
}
<?php

namespace App\Enums;
use Filament\Support\Contracts\HasLabel;

enum TitreEnum: int implements HasLabel
{
case M = 0;
case MME = 1;

public function getLabel(): ?string
{
return match ($this) {
self::M => 'M.',
self::MME => 'Mme',
};
}
}
Filament\Forms\Components\Select::getOptions(): Return value must be of type array, string returned
12 replies
FFilament
Created by Pasteko on 5/29/2023 in #❓┊help
Edit page - previous and next actions
2 replies
FFilament
Created by Pasteko on 5/24/2023 in #❓┊help
Custom widget grid and table look
Here's the view of my custom widget, how can I display cards like in the official widgets?
protected function getColumns(): int | array
{
return 2;
}
protected function getColumns(): int | array
{
return 2;
}
<x-filament::widget>
<x-filament::card>

<div class="overflow-x-auto">
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" class="px-6 py-3">
Format
</th>
<th scope="col" class="px-6 py-3">
Thème
</th>
<th scope="col" class="px-6 py-3">
Nombre
</th>
</tr>
</thead>
<tbody>
{{-- dd($orders_theme) --}}
@foreach ($orders_theme as $orders_t)
@foreach ($orders_t as $order)
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
{{ $order['product']['format']['name'] ?? 'Stickers' }}
</th>
<td class="px-6 py-4">
{{ $order['product']['theme']['name'] ?? null }}
</td>
<td class="px-6 py-4">
{{ $order['total_products'] ?? null }}
</td>
</tr>
@endforeach
@endforeach
</tbody>
</table>
</div>

</x-filament::card>
<x-filament::widget>
<x-filament::card>

<div class="overflow-x-auto">
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" class="px-6 py-3">
Format
</th>
<th scope="col" class="px-6 py-3">
Thème
</th>
<th scope="col" class="px-6 py-3">
Nombre
</th>
</tr>
</thead>
<tbody>
{{-- dd($orders_theme) --}}
@foreach ($orders_theme as $orders_t)
@foreach ($orders_t as $order)
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
{{ $order['product']['format']['name'] ?? 'Stickers' }}
</th>
<td class="px-6 py-4">
{{ $order['product']['theme']['name'] ?? null }}
</td>
<td class="px-6 py-4">
{{ $order['total_products'] ?? null }}
</td>
</tr>
@endforeach
@endforeach
</tbody>
</table>
</div>

</x-filament::card>
7 replies
FFilament
Created by Pasteko on 5/24/2023 in #❓┊help
Building an array for a custom widget
Hello, trying for two days now to solve this.
//[Order]
- id
- payment_status
public function items()
{
return $this->hasMany(OrderItem::class);
}
//[OrderItem]
- id
- order_id
- product_id
- quantity
- price
public function order()
{
return $this->belongsTo(Order::class);
}
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
//[Product]
- id
- format_id
- theme_id
public function items()
{
return $this->hasMany(OrderItem::class);
}
//[Order]
- id
- payment_status
public function items()
{
return $this->hasMany(OrderItem::class);
}
//[OrderItem]
- id
- order_id
- product_id
- quantity
- price
public function order()
{
return $this->belongsTo(Order::class);
}
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
//[Product]
- id
- format_id
- theme_id
public function items()
{
return $this->hasMany(OrderItem::class);
}

protected function getViewData(): array
{
$orders = Order::select('id')->where('payment_status', 1)
->with(['items' => function ($query) {
$query->select('order_id', 'product_id');
},
'items.product' => function ($query) {
$query->select('format_id');
}
])
->get()
->groupBy('format_id')
->toArray();

return [
'orders' => $orders
];
}

protected function getViewData(): array
{
$orders = Order::select('id')->where('payment_status', 1)
->with(['items' => function ($query) {
$query->select('order_id', 'product_id');
},
'items.product' => function ($query) {
$query->select('format_id');
}
])
->get()
->groupBy('format_id')
->toArray();

return [
'orders' => $orders
];
}
What I need is to sum the quantity of items for orders with payment_status=1 and group them by format and build the widget array like this [format][sum(quantity)]
12 replies
FFilament
Created by Pasteko on 5/18/2023 in #❓┊help
Generate a pdf from BulkAction values
Tables\Actions\Action::make('pdf')
->icon('heroicon-o-document-download')
->color('danger')
->label('PDF')
->url(fn (List $record) => route('list.pdf.download', $record))
->openUrlInNewTab(),
Tables\Actions\Action::make('pdf')
->icon('heroicon-o-document-download')
->color('danger')
->label('PDF')
->url(fn (List $record) => route('list.pdf.download', $record))
->openUrlInNewTab(),
Hello, how can y build the same document from BulkAction values with an intermediate form to set some other properties?
Tables\Actions\BulkAction::make('stickers')
->action(function (Collection $records, array $data): void {
????
????
????route('stickers.pdf.download', $data);
})
->label('Stickers')
->color('success')
->icon('heroicon-s-printer')
->modalWidth('sm')
->form([
Forms\Components\TextInput::make('start')
->numeric()
->minValue(1)
->maxValue(8)
->label('Start')
])
]);
Tables\Actions\BulkAction::make('stickers')
->action(function (Collection $records, array $data): void {
????
????
????route('stickers.pdf.download', $data);
})
->label('Stickers')
->color('success')
->icon('heroicon-s-printer')
->modalWidth('sm')
->form([
Forms\Components\TextInput::make('start')
->numeric()
->minValue(1)
->maxValue(8)
->label('Start')
])
]);
21 replies
FFilament
Created by Pasteko on 5/17/2023 in #❓┊help
Modifiy an option in a select
15 replies
FFilament
Created by Pasteko on 5/5/2023 in #❓┊help
Merge two cards with different number of columns without having borders
4 replies
FFilament
Created by Pasteko on 5/3/2023 in #❓┊help
Sum (quantity * price)
Hello, Tried for hours to get a total for orders , there's something I'm doing wrong?
public function items()
{
return $this->hasMany(OrderItem::class);
}

Forms\Components\Placeholder::make('total')
->content(fn ($record) => $record->items->sum(\DB::raw('quantity * price')))
public function items()
{
return $this->hasMany(OrderItem::class);
}

Forms\Components\Placeholder::make('total')
->content(fn ($record) => $record->items->sum(\DB::raw('quantity * price')))
or trough an attribute
public function getTotalAttribute()
{
return $this->quantity * $this->price;
}

Forms\Components\Placeholder::make('total')
->content(fn ($record) => $record->items->total)
public function getTotalAttribute()
{
return $this->quantity * $this->price;
}

Forms\Components\Placeholder::make('total')
->content(fn ($record) => $record->items->total)
37 replies
FFilament
Created by Pasteko on 4/27/2023 in #❓┊help
Sortable with nested relations
How can I use sortable with multiple relations?
return $table
->columns([
//
Tables\Columns\TextColumn::make('type.year.name')->label('Année')->sortable(),
Tables\Columns\TextColumn::make('type.name')->label('Type')->sortable(),
Tables\Columns\TextColumn::make('name')->label('Region')->sortable(),
Tables\Columns\TextColumn::make('description'),
])
return $table
->columns([
//
Tables\Columns\TextColumn::make('type.year.name')->label('Année')->sortable(),
Tables\Columns\TextColumn::make('type.name')->label('Type')->sortable(),
Tables\Columns\TextColumn::make('name')->label('Region')->sortable(),
Tables\Columns\TextColumn::make('description'),
])
when I try to sort type.year.name it gives me : Column not found: 1054 Unknown column 'pk_types.year_id' which is normal because there's no column year_id in table regions
8 replies
FFilament
Created by Pasteko on 4/23/2023 in #❓┊help
How do you call a relation attribute in form?
public function getFullNameAttribute()
{
return ucfirst($this->first_name) . ' ' . ucfirst($this->last_name);
}
public function getFullNameAttribute()
{
return ucfirst($this->first_name) . ' ' . ucfirst($this->last_name);
}
In table I just call : customer.full_name I know it's not possible that way but can't make it work.
Forms\Components\Group::make()
->relationship('customer')
->schema([
Forms\Components\TextInput::make('full_name')->disabled(),
]),
Forms\Components\Group::make()
->relationship('customer')
->schema([
Forms\Components\TextInput::make('full_name')->disabled(),
]),
13 replies
FFilament
Created by Pasteko on 4/19/2023 in #❓┊help
How do you set the name of the relation table?
3 replies
FFilament
Created by Pasteko on 4/3/2023 in #❓┊help
Is there any other way to write this?
Forms\Components\Select::make('year_id')
->options(Year::all()->pluck('year', 'id')->toArray())
->afterStateHydrated(function ($set, $state, $record) {
if (isset($record->product_id)) {
$set('year_id', Product::with('year')->where('id', $record->product_id)->value('year_id'));
}
})
->label('Year')
->reactive()
->required(),
Forms\Components\Select::make('year_id')
->options(Year::all()->pluck('year', 'id')->toArray())
->afterStateHydrated(function ($set, $state, $record) {
if (isset($record->product_id)) {
$set('year_id', Product::with('year')->where('id', $record->product_id)->value('year_id'));
}
})
->label('Year')
->reactive()
->required(),
`
28 replies
FFilament
Created by Pasteko on 4/3/2023 in #❓┊help
Is there any way chain relations with ->relationship?
Is it possible?
16 replies