Shaung Bhone
Shaung Bhone
Explore posts from servers
FFilament
Created by Shaung Bhone on 10/13/2024 in #❓┊help
url() validation gives me valid url
No description
4 replies
FFilament
Created by Shaung Bhone on 10/12/2024 in #❓┊help
Best approach to save "price" field
What is the best approach to save decimal values like price, subtotal, and total in a Laravel migration? In my app, I’m using
$table->decimal('total', 10, 2);
$table->decimal('total', 10, 2);
but since I’m using PostgreSQL, it’s not working. I’m also trying to format the values like this:
$set(
'total',
Number::format(
$subtotal,
maxPrecision: 2
)
); // The format results in something like 596,490, which isn't working for decimals.
$set(
'total',
Number::format(
$subtotal,
maxPrecision: 2
)
); // The format results in something like 596,490, which isn't working for decimals.
How can I fix this?
11 replies
FFilament
Created by Shaung Bhone on 9/21/2024 in #❓┊help
Multi Tenancy with one to many polymorphic relationship.
I got the error. I can't create the category at the filament panel
The model [App\Models\Tenant] does not have a relationship named [categories]. You can change the relationship being used by setting it as the [$tenantRelationshipName] static property on the [App\Filament\Resources\CategoryResource] resource class.
The model [App\Models\Tenant] does not have a relationship named [categories]. You can change the relationship being used by setting it as the [$tenantRelationshipName] static property on the [App\Filament\Resources\CategoryResource] resource class.
$panel->tenant(Tenant::class, ownershipRelationship: 'tenants')
$panel->tenant(Tenant::class, ownershipRelationship: 'tenants')
5 replies
FFilament
Created by Shaung Bhone on 9/14/2024 in #❓┊help
Filament with spatie event sourcing
I'm trying to create data with spatie event sourcing, when I create the data, event attribute gives me always null.
Currency.php
public static function createWithAttributes(array $attributes): self
{
$attributes['uuid'] = (string) Uuid::uuid4();

event(new CurrencyCreated(currencyAttributes: $attributes));

return static::uuid($attributes['uuid']); <-- give me null
}
Currency.php
public static function createWithAttributes(array $attributes): self
{
$attributes['uuid'] = (string) Uuid::uuid4();

event(new CurrencyCreated(currencyAttributes: $attributes));

return static::uuid($attributes['uuid']); <-- give me null
}
ListCurrencies.php
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->createAnother(false)
->using(function (array $data, string $model): Model {
return $model::createWithAttributes($data);
})
->icon('heroicon-o-plus')
->label('Create')
->modalWidth(MaxWidth::Large),
];
}
ListCurrencies.php
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->createAnother(false)
->using(function (array $data, string $model): Model {
return $model::createWithAttributes($data);
})
->icon('heroicon-o-plus')
->label('Create')
->modalWidth(MaxWidth::Large),
];
}
<?php

namespace App\Events;

use Spatie\EventSourcing\StoredEvents\ShouldBeStored;

class CurrencyCreated extends ShouldBeStored
{
public function __construct(
public array $currencyAttributes
){}
}
<?php

namespace App\Events;

use Spatie\EventSourcing\StoredEvents\ShouldBeStored;

class CurrencyCreated extends ShouldBeStored
{
public function __construct(
public array $currencyAttributes
){}
}
2 replies
FFilament
Created by Shaung Bhone on 8/29/2024 in #❓┊help
mask money comma separate is not working
Forms\Components\Select::make('product_id')
->label('Product')
->options(Product::query()->pluck('name', 'id'))
->required()
->reactive()
->afterStateUpdated(
fn(
$state,
Forms\Set $set
) => $set(
'unit_price',
Product::find($state)?->price *
Product::find($state)?->currency->rate *
(1 + Product::find($state)?->margin / 100) ?? 0,
)
)
->distinct()
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->columnSpan([
'md' => 5,
])
->searchable(),

Forms\Components\TextInput::make('qty')
->label('Quantity')
->numeric()
->default(1)
->columnSpan([
'md' => 2,
])
->required(),

Forms\Components\TextInput::make('unit_price')
->label('Unit Price')
->disabled()
->dehydrated()
->live()
->mask(RawJs::make(<<<'JS'
$money($input, '.', ',')
JS))
->numeric()
->required()
->columnSpan([
'md' => 3,
])
Forms\Components\Select::make('product_id')
->label('Product')
->options(Product::query()->pluck('name', 'id'))
->required()
->reactive()
->afterStateUpdated(
fn(
$state,
Forms\Set $set
) => $set(
'unit_price',
Product::find($state)?->price *
Product::find($state)?->currency->rate *
(1 + Product::find($state)?->margin / 100) ?? 0,
)
)
->distinct()
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->columnSpan([
'md' => 5,
])
->searchable(),

Forms\Components\TextInput::make('qty')
->label('Quantity')
->numeric()
->default(1)
->columnSpan([
'md' => 2,
])
->required(),

Forms\Components\TextInput::make('unit_price')
->label('Unit Price')
->disabled()
->dehydrated()
->live()
->mask(RawJs::make(<<<'JS'
$money($input, '.', ',')
JS))
->numeric()
->required()
->columnSpan([
'md' => 3,
])
21 replies
FFilament
Created by Shaung Bhone on 8/22/2024 in #❓┊help
Placeholder component with relationship
I'm trying to show all the value when user creating invoice in the wizard. user name is not showing. How can I show invoice belong to user?
Forms\Components\Wizard\Step::make('Reviews')
->schema([
Forms\Components\Placeholder::make('number')
->content(fn($get) => $get('number')),
Forms\Components\Placeholder::make('user') <-- not working give me null
->content(fn($get) => $get('name')),
Forms\Components\Placeholder::make('note')
->content(
fn($get)
=> new HtmlString($get('note'))
),
]),
Forms\Components\Wizard\Step::make('Reviews')
->schema([
Forms\Components\Placeholder::make('number')
->content(fn($get) => $get('number')),
Forms\Components\Placeholder::make('user') <-- not working give me null
->content(fn($get) => $get('name')),
Forms\Components\Placeholder::make('note')
->content(
fn($get)
=> new HtmlString($get('note'))
),
]),
9 replies
FFilament
Created by Shaung Bhone on 8/4/2024 in #❓┊help
Testing filament resource table got an error
I got an error when testing a filament resource table like that! I don't know why?. I just copied the code from filament resource testing documentation.
lse,&quot;except&quot;:null},&quot;defaultTableActionRecord&quot;:{&quot;as&quot;:&quot;tableActionRecord&quot;,&quot;use&quot;:&quot;replace&quot;,&quot;alwaysShow&quot;:false,&quot;except&quot;:null},&quot;paginators.page&quot;:{&quot;as&quot;:&quot;page&quot;,&quot;use&quot;:&quot;push&quot;,&quot;alwaysShow&quot;:false,&quot;except&quot;:null}}}" wire:id="7e0WsZp5wPL6t4HSQntg"\n
class="fi-page fi-resource-list-records-page fi-resource-categories"\n
>\n
... (3480 more lines)

To contain: 7e0WsZp5wPL6t4HSQntg.table.records.11

at vendor/livewire/livewire/src/Features/SupportTesting/MakesAssertions.php:38
34▕
35▕ function assertSeeHtml($values)
36▕ {
37▕ foreach (Arr::wrap($values) as $value) {
➜ 38▕ PHPUnit::assertStringContainsString(
39▕ $value,
40▕ $this->html()
41▕ );
42▕ }

+4 vendor frames
5 tests/Feature/filament/CategoryResourceTest.php:43
lse,&quot;except&quot;:null},&quot;defaultTableActionRecord&quot;:{&quot;as&quot;:&quot;tableActionRecord&quot;,&quot;use&quot;:&quot;replace&quot;,&quot;alwaysShow&quot;:false,&quot;except&quot;:null},&quot;paginators.page&quot;:{&quot;as&quot;:&quot;page&quot;,&quot;use&quot;:&quot;push&quot;,&quot;alwaysShow&quot;:false,&quot;except&quot;:null}}}" wire:id="7e0WsZp5wPL6t4HSQntg"\n
class="fi-page fi-resource-list-records-page fi-resource-categories"\n
>\n
... (3480 more lines)

To contain: 7e0WsZp5wPL6t4HSQntg.table.records.11

at vendor/livewire/livewire/src/Features/SupportTesting/MakesAssertions.php:38
34▕
35▕ function assertSeeHtml($values)
36▕ {
37▕ foreach (Arr::wrap($values) as $value) {
➜ 38▕ PHPUnit::assertStringContainsString(
39▕ $value,
40▕ $this->html()
41▕ );
42▕ }

+4 vendor frames
5 tests/Feature/filament/CategoryResourceTest.php:43
CategoryResourceTest.php
it('can list categories table', function () {
$categories = Category::factory()->count(10)->create();

livewire(CategoryResource\Pages\ListCategories::class)
->assertCanSeeTableRecords($categories);
});
it('can list categories table', function () {
$categories = Category::factory()->count(10)->create();

livewire(CategoryResource\Pages\ListCategories::class)
->assertCanSeeTableRecords($categories);
});
2 replies
FFilament
Created by Shaung Bhone on 6/7/2024 in #❓┊help
Pesting form builder with upload file
No description
13 replies
FFilament
Created by Shaung Bhone on 3/23/2024 in #❓┊help
One to many polymorphic relationship
No description
4 replies
FFilament
Created by Shaung Bhone on 3/13/2024 in #❓┊help
Using tab in custom page
How can I use filter tab in livewire component? I saw this converstaion but got an error. https://github.com/filamentphp/filament/discussions/10127
1 replies
FFilament
Created by Shaung Bhone on 3/11/2024 in #❓┊help
Can't save form action
I can't save the value in advanced form action that give me null.
Forms\Components\TextInput::make('remaining_stock')
->disabled()
->suffixAction(
Action::make('addingNewStock')
->label('Add New Stock')
->icon('heroicon-m-plus')
->requiresConfirmation()
->form([
Forms\Components\TextInput::make('adding_stock')
->numeric()
->rules(['integer', 'min:0'])
])
->modalIcon('heroicon-m-plus')
->action(function (
Forms\Set $set, Get $get, array $data
): void {
$set(
'remaining_stock',
$get('remaining_stock') + $data['adding_stock']);
})
)
Forms\Components\TextInput::make('remaining_stock')
->disabled()
->suffixAction(
Action::make('addingNewStock')
->label('Add New Stock')
->icon('heroicon-m-plus')
->requiresConfirmation()
->form([
Forms\Components\TextInput::make('adding_stock')
->numeric()
->rules(['integer', 'min:0'])
])
->modalIcon('heroicon-m-plus')
->action(function (
Forms\Set $set, Get $get, array $data
): void {
$set(
'remaining_stock',
$get('remaining_stock') + $data['adding_stock']);
})
)
30 replies
FFilament
Created by Shaung Bhone on 3/8/2024 in #❓┊help
Table with image
No description
4 replies
FFilament
Created by Shaung Bhone on 3/5/2024 in #❓┊help
Boolean status
How can I change boolean status to Yes or No lable in Table Column?
3 replies
FFilament
Created by Shaung Bhone on 2/28/2024 in #❓┊help
Custome theme for table
No description
4 replies
FFilament
Created by Shaung Bhone on 2/8/2024 in #❓┊help
Creating with pivot attributes
I can't create pivot value when creating sku. Sku.php
public function attributes(): BelongsToMany
{
return $this->belongsToMany(Attribute::class, 'attribute_sku')->withPivot('value');
}
public function attributes(): BelongsToMany
{
return $this->belongsToMany(Attribute::class, 'attribute_sku')->withPivot('value');
}
Attribute.php
public function skus(): BelongsToMany
{
return $this->belongsToMany(Sku::class, 'attribute_sku')->withPivot('value');
}
public function skus(): BelongsToMany
{
return $this->belongsToMany(Sku::class, 'attribute_sku')->withPivot('value');
}
SkusRelationManager.php
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('sku')
->required()
->maxLength(255),
Forms\Components\Select::make('attribute_sku')
->relationship('attributes', 'name'),
Forms\Components\TextInput::make('value'),
]);
}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('sku')
->required()
->maxLength(255),
Forms\Components\Select::make('attribute_sku')
->relationship('attributes', 'name'),
Forms\Components\TextInput::make('value'),
]);
}
2 replies
FFilament
Created by Shaung Bhone on 2/7/2024 in #❓┊help
Filament shield
When I install filament shield php artisan shield:install . I want to get multiple role editor and writer. How can I?
5 replies
FFilament
Created by Shaung Bhone on 11/30/2023 in #❓┊help
Filament noti in livewire component
I'm trying to send a filament notification in a Livewire component when a user creates a post, redirects to the home page, and displays the notification on the home page. How can I? Can I dispatch event or sth?
16 replies
FFilament
Created by Shaung Bhone on 11/28/2023 in #❓┊help
Filament Spatie FileUpload with s3
No description
15 replies
FFilament
Created by Shaung Bhone on 11/28/2023 in #❓┊help
Filter and Search
Can I use filament filter and search in front end?
1 replies
FFilament
Created by Shaung Bhone on 11/25/2023 in #❓┊help
Livewire component event
In the Laravel Livewire boot camp, when creating chirps, the author dispatches an event! In my code, should I need to dispatch an event?
public function create(): void
{
abort_if(auth()->guest(), Response::HTTP_FORBIDDEN);

$resume = Auth::user()
->resume()
->create($this->form->getState());

$this->form->model($resume)->saveRelationships();

$this->redirect('/resume');
}
public function create(): void
{
abort_if(auth()->guest(), Response::HTTP_FORBIDDEN);

$resume = Auth::user()
->resume()
->create($this->form->getState());

$this->form->model($resume)->saveRelationships();

$this->redirect('/resume');
}
2 replies