Mdk
Mdk
FFilament
Created by Mdk on 3/29/2024 in #❓┊help
Including a relationship form from a different Resource doesn't display repeater items in it
I'm trying to cut down on my duplicated code, so inside a OrderResource I created this method
public static function getProductsForm()
{
return [
Forms\Components\Repeater::make('orderProducts')
->relationship('orderProducts')
->schema([
Forms\Components\Select::make('product_id')
->relationship('product', 'name',
modifyQueryUsing: fn (Builder $query) => $query->enabled())
->live()
->searchable()
->preload()
[....]
]),
Forms\Components\TextInput::make('discount')
->numeric()
->rules(['regex:/^\d{1,6}(\.\d{0,2})?$/'])
->minValue(0)
->suffix('€'),
Forms\Components\TextInput::make('total')
->label('Total')
->disabled()
->readOnly()
->dehydrated(false)
];
}
public static function getProductsForm()
{
return [
Forms\Components\Repeater::make('orderProducts')
->relationship('orderProducts')
->schema([
Forms\Components\Select::make('product_id')
->relationship('product', 'name',
modifyQueryUsing: fn (Builder $query) => $query->enabled())
->live()
->searchable()
->preload()
[....]
]),
Forms\Components\TextInput::make('discount')
->numeric()
->rules(['regex:/^\d{1,6}(\.\d{0,2})?$/'])
->minValue(0)
->suffix('€'),
Forms\Components\TextInput::make('total')
->label('Total')
->disabled()
->readOnly()
->dehydrated(false)
];
}
Calling it from the OrderResource itself works fine, but now I'm also adding it to a different resource, ShipmentResource
Forms\Components\Section::make()
->heading(__('Order informations'))
->relationship('order')
->headerActions([
Forms\Components\Actions\Action::make('openShipment')
->label(__('View Order'))
->url(fn($record) => OrderResource::getUrl('edit', ['record' => $record->order->id]))
])
->schema([
Forms\Components\Group::make()
->columnSpanFull()
->columns(2)
->schema(OrderResource::getOrderForm()),
Forms\Components\Group::make()
->columnSpanFull()
->columns(2)
->schema(OrderResource::getProductsForm())
]),
Forms\Components\Section::make()
->heading(__('Order informations'))
->relationship('order')
->headerActions([
Forms\Components\Actions\Action::make('openShipment')
->label(__('View Order'))
->url(fn($record) => OrderResource::getUrl('edit', ['record' => $record->order->id]))
])
->schema([
Forms\Components\Group::make()
->columnSpanFull()
->columns(2)
->schema(OrderResource::getOrderForm()),
Forms\Components\Group::make()
->columnSpanFull()
->columns(2)
->schema(OrderResource::getProductsForm())
]),
Thing is, the order details are displayed fine, the discount and total as well, but the repeater is not showing at all (unless I make it non-disabled, then the add button appears)
73 replies
FFilament
Created by Mdk on 10/31/2023 in #❓┊help
Filling a SpatieMediaLibraryImageEntry field programmatically on a new Model (not saved yet)
I'm trying to set up a "cloning" functionality where the user can pick an existing Item and make a copy that he can edit before saving it as his own I made a copy of the CreateRecord page that accept an extra param (the ID of the item to be cloned) and added this
protected function afterFill(): void
{
$item = Item::findOrFail($this->item);
$this->data['status'] = 'enabled';
$this->data['title'] = $item->title;
$this->data['description'] = $item->description;
}
protected function afterFill(): void
{
$item = Item::findOrFail($this->item);
$this->data['status'] = 'enabled';
$this->data['title'] = $item->title;
$this->data['description'] = $item->description;
}
So far so good, but my Items also have images attached, via the SpatieMediaLibrary plugin, and I can't find a way to bring the original item's images in the form I thought about persisting the item to the database and then using the EditRecord page but that would be extra clutter in case the user doesn't actually save his item anymore Any other way to auto-fill that field from existing images (that would then have to be copied over to new Model as well)?
8 replies
FFilament
Created by Mdk on 10/26/2023 in #❓┊help
Custom Action that calls "save" doesn't actually save the model
So I'm trying to put a save button elsewhere in an Edit page
Grid::make('card_payment')
->visible(fn($get) => $get('payment_method') === 'card')
->schema([
TextInput::make('balance_used')
->label(__uf('use balance'))
->hint(__uf('balance available').': '.money(auth()->user()->balance, env('CASHIER_CURRENCY')))
->numeric()
->minValue(0)
->maxValue(auth()->user()->balance)
->live(debounce:500)
//->afterStateUpdated(fn($state) => dump($state))
->prefix('€'),
Actions::make([
Actions\Action::make('paybycard')
->label(fn($record, $get) =>
__uf('proceed to payment').' - '.money($record->order_total + $record->shipping_cost - ($get('balance_to_use')?:0), env('CASHIER_CURRENCY')))
->submit('save')
])->fullWidth()
])
Grid::make('card_payment')
->visible(fn($get) => $get('payment_method') === 'card')
->schema([
TextInput::make('balance_used')
->label(__uf('use balance'))
->hint(__uf('balance available').': '.money(auth()->user()->balance, env('CASHIER_CURRENCY')))
->numeric()
->minValue(0)
->maxValue(auth()->user()->balance)
->live(debounce:500)
//->afterStateUpdated(fn($state) => dump($state))
->prefix('€'),
Actions::make([
Actions\Action::make('paybycard')
->label(fn($record, $get) =>
__uf('proceed to payment').' - '.money($record->order_total + $record->shipping_cost - ($get('balance_to_use')?:0), env('CASHIER_CURRENCY')))
->submit('save')
])->fullWidth()
])
Both payment_method and balance_used are properties of the model that is being edited I tried with both submit('save') as well as action('save'), they both trigger the validation and display the success notification, but the model is not updated and neither protected function beforeSave() or protected function afterSave() are called.. what am I doing wrong? My plan was to save the order and then redirect to the payment page in the afterSave method, I would've used a custom action but I couldn't manage to trigger the validation with that
5 replies
FFilament
Created by Mdk on 10/23/2023 in #❓┊help
Custom theme missing some default classes
Brand new installation (but this happened on previous setups too), I just made a custom theme and as soon as I switch to it, the various items' gray borders disappear, be it the small search input above the tables or the whole container that holds the table itself I've narrowed it down to not having these 2 declarations in my CSS:
.ring-1,.ring-2 {
box-shadow: var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000);
}
.ring-1,.ring-2 {
box-shadow: var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000);
}
.shadow-sm,.shadow-xl {
box-shadow: var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)
}
.shadow-sm,.shadow-xl {
box-shadow: var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)
}
My tailwind config is the default one, adapted just the paths to my custom panel (shop), but these classes should be in the default filament blades, not custom ones
import preset from '../../../../vendor/filament/filament/tailwind.config.preset'

export default {
presets: [preset],
content: [
'./app/Filament/Shop/**/*.php',
'./resources/views/filament/shop/**/*.blade.php',
'./vendor/filament/**/*.blade.php',
],
}
import preset from '../../../../vendor/filament/filament/tailwind.config.preset'

export default {
presets: [preset],
content: [
'./app/Filament/Shop/**/*.php',
'./resources/views/filament/shop/**/*.blade.php',
'./vendor/filament/**/*.blade.php',
],
}
23 replies
FFilament
Created by Mdk on 10/18/2023 in #❓┊help
Filament + Jetstream + multiple LDAP domains, how to login?
I'm currently trying to set up Filament along a Jetstream with a multi domain LDAP login system So far, Jetstream's login page has been edited to include a domain selector, and the login works fine, I get redirected to the /dashboard page on a successful attempt I'm now trying to put Filament in the mix, but as soon as I try to access its path, I get 302'd to /login and then back to /dashboard since the user is indeed logged in, but Filament refuses to recognize the session
70 replies
FFilament
Created by Mdk on 8/31/2023 in #❓┊help
Preload a relationship select if a parent select has a value
I'm currently creating a form where the user can pick an item, either by starting from the very first category and filtering it down or just searching in the entire catalogue Each select is searchable, and results are filtered according to the previous one (if something is selected), but for added user-friendlyness I'd like to also show the first 50 or so items in child selects if they're already filtered down I tried using ->preload(fn($get) => $get('category_id')) on a child select with and without ->live() but neither had any impact
2 replies
FFilament
Created by Mdk on 8/10/2023 in #❓┊help
Empty CSS when creating a new theme, not extending the default
was trying to create a new theme to overwrite just a few rules, followed all the instructions but I'm getting a basically empty CSS file resources/css/filament/admin/theme.css:
@import '../../../../vendor/filament/filament/resources/css/theme.css';

@config './tailwind.config.js';

.fi-sidebar {
background: white;
border-right: 1px solid #E4E4E5;
}

.dark .fi-sidebar {
background: #18181B;
border-right: 1px solid #2F2F31;
}
@import '../../../../vendor/filament/filament/resources/css/theme.css';

@config './tailwind.config.js';

.fi-sidebar {
background: white;
border-right: 1px solid #E4E4E5;
}

.dark .fi-sidebar {
background: #18181B;
border-right: 1px solid #2F2F31;
}
That first link (theme.css) contains just this:
@import 'index.css';
@import 'index.css';
That one, if opened, contains this:
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
html {
-webkit-tap-highlight-color: transparent;
}

:root.dark {
color-scheme: dark;
}
}
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
html {
-webkit-tap-highlight-color: transparent;
}

:root.dark {
color-scheme: dark;
}
}
I did run build, but as soon as I add ->viteTheme('resources/css/filament/admin/theme.css') to the AdminPanelProvider I'm getting the ugliest site ever What am I missing?
52 replies
FFilament
Created by Mdk on 8/4/2023 in #❓┊help
Setting recordUrl(null) on a table that has an EditAction among its action doesn't disable the click
I haven't had time to fully test this, but my scenario is this:
$table
[..]
->actions([
Tables\Actions\Action::make('view product')
->label('Vedi prodotto')
->url(fn (Watchlist $record): string => ProductResource::getUrl('view', ['record' => $record->product_id]))
->color('gray')
->icon('heroicon-s-eye'),
Tables\Actions\EditAction::make(),
])
$table
[..]
->actions([
Tables\Actions\Action::make('view product')
->label('Vedi prodotto')
->url(fn (Watchlist $record): string => ProductResource::getUrl('view', ['record' => $record->product_id]))
->color('gray')
->icon('heroicon-s-eye'),
Tables\Actions\EditAction::make(),
])
I wanted to disabled the row click, but using ->recordUrl(null) doesn't work, UNLESS i remove the EditAction as well (the custom action doesn't seem to have any influence in all of this) Is this an expected behaviour? I want to keep the edit action in the last column while not giving the user the option to click the whole row
4 replies
FFilament
Created by Mdk on 8/1/2023 in #❓┊help
Show related entity's details in an RelationManager edit modal
I have 3 entities, Customer, Product and Wishlist, with the latter having both product_id and customer_id in it I'm trying to show a customer's wishlist in its details page, which works fine inside the RelationManager table by just using product.title and product.price, but when I go edit this relation those 2 fields are emtpy (while other fields that are directly on the wishlist table are shown fine) What am I missing here? Why does it work in the table but not in the form?
6 replies
FFilament
Created by Mdk on 7/5/2023 in #❓┊help
How to display and update pivot field in attach/edit form?
I've got a table, Places, that has a name and a description fields among other, and it's linked to an Itinerary table through a pivot, Itinerary_Place. This pivot table also has both name and description, so I can override the default ones when attaching a place to an itinerary. I can't find a way to display AND update the pivot name/description though, I can either display it by using make('pivot_name') but then it fails when it's time to save, or I can use make('name') and it'll update the correct field in the pivot table but it will always display the place's original name (same goes for the description) What am I missing?
6 replies