pratik
pratik
FFilament
Created by toeknee on 11/5/2024 in #❓┊help
Relationship with a relationship after create?
And then in createPurchase
protected function handleRecordCreation(array $data): Model
{
$model = static::getModel()::create(Arr::except($data, ['due']));

if ($data['due'] > 0) {
$model->due()
->create([
'amount' => $data['due'],
'status' => PaymentStatus::Due,
]);
}

return $model;
}
protected function handleRecordCreation(array $data): Model
{
$model = static::getModel()::create(Arr::except($data, ['due']));

if ($data['due'] > 0) {
$model->due()
->create([
'amount' => $data['due'],
'status' => PaymentStatus::Due,
]);
}

return $model;
}
21 replies
FFilament
Created by toeknee on 11/5/2024 in #❓┊help
Relationship with a relationship after create?
I managed to do it like this 😀
Hidden::make('due')
->dehydrateStateUsing(function ($get) {
$purchase_total = (float) $get('total_amount');

$discount_amount = (float) $get('discount_amount');

$tax_amount = (float) $get('tax_amount');

$total = $purchase_total - $discount_amount + $tax_amount;

$payments = $get('payments');

$total_paid = 0;

foreach ($payments as $payment) {
$total_paid = $total_paid + (float) $payment['amount'];
}

$due = round($total - $total_paid, 2);

return $due;
})
->default(0),
Hidden::make('due')
->dehydrateStateUsing(function ($get) {
$purchase_total = (float) $get('total_amount');

$discount_amount = (float) $get('discount_amount');

$tax_amount = (float) $get('tax_amount');

$total = $purchase_total - $discount_amount + $tax_amount;

$payments = $get('payments');

$total_paid = 0;

foreach ($payments as $payment) {
$total_paid = $total_paid + (float) $payment['amount'];
}

$due = round($total - $total_paid, 2);

return $due;
})
->default(0),
21 replies
FFilament
Created by toeknee on 11/5/2024 in #❓┊help
Relationship with a relationship after create?
Manipulating due amount is not a concern actually. It's an internal system.
21 replies
FFilament
Created by toeknee on 11/5/2024 in #❓┊help
Relationship with a relationship after create?
I just got an idea while typing this, i can create a due hidden field, then I can use dehydrateStateusing and do my calculations there and customize the creation process to record the due. ? does this sound good ?
21 replies
FFilament
Created by toeknee on 11/5/2024 in #❓┊help
Relationship with a relationship after create?
I am creating a new purchase, purchase has many payments that is being created with purchase using repeater. Then I need to access the total paid amount i.e sum of amount from multiple payments records and subtract it from total purchase amount to calculate due. My goal is to record this due amount in payments_due table. Using observer hasn't been much help as the payments is not created when purchase created event is fired.
21 replies
FFilament
Created by toeknee on 11/5/2024 in #❓┊help
Relationship with a relationship after create?
Hey @toeknee Exact same scenario, I need to do something after the repeater relationship has been created. How did you manage to do it ?
21 replies
FFilament
Created by Amir on 11/29/2024 in #❓┊help
Repeater afterStateUpdated
@Amir figured it out yet mate ?
8 replies
FFilament
Created by elben on 1/8/2025 in #❓┊help
How to trigger an action from another action?
Idk about that but How I got this working was registering actions with getActions method
protected function getActions(): array
{
return [
self::EditFieldAction(),
];
}

#[On('field-clicked')]
public function showFieldEditor($field_id)
{
$this->mountAction('edit-field', ['field' => $field_id]);
}
protected function getActions(): array
{
return [
self::EditFieldAction(),
];
}

#[On('field-clicked')]
public function showFieldEditor($field_id)
{
$this->mountAction('edit-field', ['field' => $field_id]);
}
element.setAttribute("onclick",`Livewire.dispatch('field-clicked',[${field.id}])`);
element.setAttribute("onclick",`Livewire.dispatch('field-clicked',[${field.id}])`);
The thing is to mount the desired action when something happens.
6 replies
FFilament
Created by elben on 1/8/2025 in #❓┊help
How to trigger an action from another action?
$this->mountAction('edit-report', ['report' => $report->id]);
6 replies
FFilament
Created by pratik on 12/18/2024 in #❓┊help
Undefined array key name despite having validation
I remember that it was to return the $customer->id back to the select and get the newly created customer selected . The default wasn't working. By working I mean, the customer name wasn't showing up as selected in select field and it was empty. I removed this extra bit of code from the original message due to character limitation.
->getSearchResultsUsing(fn(string $search): array => Customer::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray())
->getOptionLabelUsing(function ($value) {
$customer = Customer::find($value);

return $customer?->name . ' ' . $customer?->address;
})
->getSearchResultsUsing(fn(string $search): array => Customer::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray())
->getOptionLabelUsing(function ($value) {
$customer = Customer::find($value);

return $customer?->name . ' ' . $customer?->address;
})
3 replies
FFilament
Created by pratik on 12/2/2024 in #❓┊help
Any way to make checkbox readonly but not disabled ?
Thank you, I missed dehydrated. 😁
5 replies
FFilament
Created by RMK147 on 10/3/2024 in #❓┊help
Form Builder Block & Spatie Media Library
5 replies
FFilament
Created by Adnan Yalahow on 5/12/2024 in #❓┊help
Can I create something like this in filament
@Adnan Yalahow Filament way is the TALL way. create custom filament page with custom view, Create blade components, use tailwind for styles, use Filament Modals, Filament actions and sprinkle some livewire and alpinejs. Here are some useful blade components mentioned in the documentation : https://filamentphp.com/docs/3.x/support/blade-components/overview
4 replies
FFilament
Created by xerk4497 on 5/11/2024 in #❓┊help
Create Policies for each Auth Model (Multi Panels)
If you are trying to achieve different polices for different panels you can do something like this in AuthServiceProvider:
use Illuminate\Support\Facades\Gate;

Gate::guessPolicyNamesUsing(function ($modelClass) {
return str($modelClass)
->replace(
search: 'App\Models\\'.str(filament()->getCurrentPanel()- >getId())->studly(),
replace: 'App\Policies\\'.str(filament()->getCurrentPanel()->getId())->studly()
)
->append('Policy')
->toString();
});

$this->registerPolicies();
use Illuminate\Support\Facades\Gate;

Gate::guessPolicyNamesUsing(function ($modelClass) {
return str($modelClass)
->replace(
search: 'App\Models\\'.str(filament()->getCurrentPanel()- >getId())->studly(),
replace: 'App\Policies\\'.str(filament()->getCurrentPanel()->getId())->studly()
)
->append('Policy')
->toString();
});

$this->registerPolicies();
Suppose you have two panel providers, AdminPanelProvider and CustomerPanelProvider, To use this implementation, you should have Admin related Models in App\Models\Admin directory and Customer related models in App\Models\Customer directory. Also, Admin related policies in App\Policies\Admin and Customer related policies in App\Policies\Customer directory. The directory name is based on Panel's id.
5 replies
FFilament
Created by Sayy on 5/11/2024 in #❓┊help
Error when select data with afterstateupdated
From as much as I understand, This simple if condition will solve your problem.
->afterStateUpdated(function ($state) {
if($state){
$product = Product::find($state);
$this->record->orderDetails()->updateOrCreate(
[
'order_id' => $this->record->id,
'product_id' => $state,
],
[
'product_id' => $state,
'quantity' => $this->quantityValue,
'price' => $product->price,
'subtotal' => $product->price * $this->quantityValue,
]
);
}
}),
->afterStateUpdated(function ($state) {
if($state){
$product = Product::find($state);
$this->record->orderDetails()->updateOrCreate(
[
'order_id' => $this->record->id,
'product_id' => $state,
],
[
'product_id' => $state,
'quantity' => $this->quantityValue,
'price' => $product->price,
'subtotal' => $product->price * $this->quantityValue,
]
);
}
}),
11 replies
FFilament
Created by blink on 5/11/2024 in #❓┊help
File (image) upload preview as grid
6 replies
FFilament
Created by Sayy on 5/11/2024 in #❓┊help
Error when select data with afterstateupdated
There is no selected product ($state is null) after you clear the select field, what are you trying to achieve when no product is selected ? you can just check if the $state is not null and wrap the logic in the condition.
11 replies
FFilament
Created by jkbcoder on 5/10/2024 in #❓┊help
Modal Footer
3 replies
FFilament
Created by Roland Barkóczi on 5/11/2024 in #❓┊help
Update RichEditor based on other field
@rolandbarkoczi Can you check again, The same code is working on my machine, and click outside the input field after you have finished typing in Prompt field.
6 replies
FFilament
Created by Sayy on 5/11/2024 in #❓┊help
Error when select data with afterstateupdated
@Sayy let's dd the product after, $product = Product::find($state); and find out if the product is not null .
11 replies