HGalih
HGalih
FFilament
Created by HGalih on 2/9/2025 in #❓┊help
Table data is not refreshed after clicking custom table action
For some reason it takes a reload to get the live data from the table after I perform a custom action. Attached is my custom action code
Tables\Actions\Action::make('Check')
->icon('heroicon-o-check-circle')
->action(function(BocomVoucher $record){
$url = "http://MYAPI:3606/validate";
$data = array(
"vouchers" => [
$record->voucher
]
)
$json_data = json_encode($data)
$ch = curl_init($url);
if(curl_errno($ch)) {
dd('cURL error: ' . curl_error($ch));
} else {
$response = json_decode($response);
$responseData = $response[0];
if(str_contains($responseData->message, 'expired')){
$record->status = 3;
}
else if(str_contains($responseData->message, 'entering')){
$record->status = 2;
}
curl_close($ch);
})
Tables\Actions\Action::make('Check')
->icon('heroicon-o-check-circle')
->action(function(BocomVoucher $record){
$url = "http://MYAPI:3606/validate";
$data = array(
"vouchers" => [
$record->voucher
]
)
$json_data = json_encode($data)
$ch = curl_init($url);
if(curl_errno($ch)) {
dd('cURL error: ' . curl_error($ch));
} else {
$response = json_decode($response);
$responseData = $response[0];
if(str_contains($responseData->message, 'expired')){
$record->status = 3;
}
else if(str_contains($responseData->message, 'entering')){
$record->status = 2;
}
curl_close($ch);
})
2 replies
FFilament
Created by HGalih on 2/3/2025 in #❓┊help
Select with relationship inside repeater return null.
This must be something really stupid. But I've triple check all the relationship naming. TradingPostResource.php
Forms\Components\Repeater::make('trading_post_periodes')
->columnSpanFull()
->schema([
Select::make('periode_id')
->required()
->relationship('periode', 'periode_name'),
Forms\Components\TextInput::make('capacity')
->required()
->numeric()
->default(25),
]),
]);
Forms\Components\Repeater::make('trading_post_periodes')
->columnSpanFull()
->schema([
Select::make('periode_id')
->required()
->relationship('periode', 'periode_name'),
Forms\Components\TextInput::make('capacity')
->required()
->numeric()
->default(25),
]),
]);
TradingPostPeriode.php
public function periode()
{
return $this->belongsTo(Periode::class);
}
public function periode()
{
return $this->belongsTo(Periode::class);
}
Error
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in C:\Users\hanin\OneDrive\Documents\Eternity9\vendor\filament\forms\src\Components\Select.
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in C:\Users\hanin\OneDrive\Documents\Eternity9\vendor\filament\forms\src\Components\Select.
4 replies
FFilament
Created by HGalih on 2/4/2024 in #❓┊help
Conditional Resource/Navigation Label
No description
5 replies
FFilament
Created by HGalih on 2/4/2024 in #❓┊help
get new repeater item only filament when editing
I want to decrease user balance everytime they order. This is what I did
protected function mutateFormDataBeforeCreate(array $data): array
{
$user = Auth::user();
$data['user_id'] = $user->id;
if(auth()->user()->balance < $data['total_price'])
throw new \Exception('Insufficient balance');

foreach ($this->data['paket_bot'] as &$value) {
$package = \App\Models\BotPackage::find($value['bot_package_id']);
$value['expired_at'] = now()->addDays($package->day_count);
if($value['quantity'] < 1) $value['quantity'] = 1;
$value['price'] = $package->discounted * $value['quantity'];
}

$user->decreaseOrIncreaseBalance(-$data['total_price']);
return $data;
}
protected function mutateFormDataBeforeCreate(array $data): array
{
$user = Auth::user();
$data['user_id'] = $user->id;
if(auth()->user()->balance < $data['total_price'])
throw new \Exception('Insufficient balance');

foreach ($this->data['paket_bot'] as &$value) {
$package = \App\Models\BotPackage::find($value['bot_package_id']);
$value['expired_at'] = now()->addDays($package->day_count);
if($value['quantity'] < 1) $value['quantity'] = 1;
$value['price'] = $package->discounted * $value['quantity'];
}

$user->decreaseOrIncreaseBalance(-$data['total_price']);
return $data;
}
'paket_bot' is a repeater that hold product datas. The catch is they can also update it (add more product but not delete previous product). And if they do add another product, I need to decrease the balance again. How do I avoid decreasing the user balance for the previous ordered item? (because repeater hold both old and new product data)
2 replies
FFilament
Created by HGalih on 2/3/2024 in #❓┊help
Very simple mutate data before create. But it is not working
It must be a very stupid mistake. This is a fresh filament and I just want to implement a very simple feature that auto assign role column for user
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
Forms\Components\TextInput::make('password')
->password()
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->dehydrated(fn ($state) => filled($state))
->required(fn (string $context): bool => $context === 'create'),
Forms\Components\TextInput::make('balance')
->label('Starting Balance')
->required()
->numeric()
->hidden(fn (string $context): bool => $context !== 'create')
->default(0),
Forms\Components\TextInput::make('percentage_discount')
->required()
->numeric()
->default(0),
Forms\Components\TextInput::make('fixed_discount')
->required()
->numeric()
->default(0),

]);


}

protected function mutateFormDataBeforeCreate(array $data): array
{
$data['role'] = 1;

return $data;
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
Forms\Components\TextInput::make('password')
->password()
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->dehydrated(fn ($state) => filled($state))
->required(fn (string $context): bool => $context === 'create'),
Forms\Components\TextInput::make('balance')
->label('Starting Balance')
->required()
->numeric()
->hidden(fn (string $context): bool => $context !== 'create')
->default(0),
Forms\Components\TextInput::make('percentage_discount')
->required()
->numeric()
->default(0),
Forms\Components\TextInput::make('fixed_discount')
->required()
->numeric()
->default(0),

]);


}

protected function mutateFormDataBeforeCreate(array $data): array
{
$data['role'] = 1;

return $data;
}
Return error
SQLSTATE[HY000]: General error: 1364 Field 'role' doesn't have a default value
SQLSTATE[HY000]: General error: 1364 Field 'role' doesn't have a default value
And ofcourse I already defined 'role' ass fillable on my user.php
11 replies
FFilament
Created by HGalih on 12/6/2023 in #❓┊help
--generate to use Select Field instead of Text Input for foreign key?
Anyway to make --generate command to use select column with relationship instead of text input where we need to fill in id for foreign keys column
4 replies
FFilament
Created by HGalih on 11/28/2023 in #❓┊help
Fillament store asset url referencing wrong domain.
Hi for some reason fillament reference the wrong domain. I duplicated my laravel project and put it in anothe rdomain. When displaying an image, it instead reference to my old domain. I have make sure that .env file is setup up properly with my new domain. Anything else needed?
2 replies
FFilament
Created by HGalih on 11/27/2023 in #❓┊help
Filament Reactive not Working
My repeater component visibility and requiribility is dependant of my select component. What I do: 1. Make both element reactive 2. Use Callable $get What I expect: 1. It start with the repeater showing because default value is 1 2. As soon as I change my select value, repeater become hidden because value is no longer 1 3. As soon as I put it back to 1, the repeater pops up back Problem: 1. Works perfectly 2. Works Perfectly 3. Doesn't want to show it anymore at all Code:
public static function form(Form $form): Form
{
return $form
->columns(3)
->schema([
Forms\Components\Select::make('exercise_type_id')->label("Question Type")
->relationship('exerciseType', 'name')
->reactive()
->default(1)
->required(),
Forms\Components\RichEditor::make("question")->columnSpan(3)->required(),
Forms\Components\RichEditor::make("explanation")->columnSpan(3),
Repeater::make('answerlist')
->defaultItems(4)
->relationship('multipleChoiceAnswers')
->label("Multiple Choice Answer Option")
->grid(2)
->schema([
Forms\Components\TextInput::make('text')->label("Text Answer"),
Forms\Components\FileUpload::make('img')->label("Image Answer")
->directory('module-images')
->storeFileNamesIn("original_filename"),
Forms\Components\Checkbox::make('is_correct_option')->label("Mark Answer As Correct")->default(false),
])->columnSpan(3)->required(fn(Callable $get) => ($get('exercise_type_id') == 1))->hidden(fn(Callable $get) => ($get('exercise_type_id') !== 1))->reactive(),
]);
}
public static function form(Form $form): Form
{
return $form
->columns(3)
->schema([
Forms\Components\Select::make('exercise_type_id')->label("Question Type")
->relationship('exerciseType', 'name')
->reactive()
->default(1)
->required(),
Forms\Components\RichEditor::make("question")->columnSpan(3)->required(),
Forms\Components\RichEditor::make("explanation")->columnSpan(3),
Repeater::make('answerlist')
->defaultItems(4)
->relationship('multipleChoiceAnswers')
->label("Multiple Choice Answer Option")
->grid(2)
->schema([
Forms\Components\TextInput::make('text')->label("Text Answer"),
Forms\Components\FileUpload::make('img')->label("Image Answer")
->directory('module-images')
->storeFileNamesIn("original_filename"),
Forms\Components\Checkbox::make('is_correct_option')->label("Mark Answer As Correct")->default(false),
])->columnSpan(3)->required(fn(Callable $get) => ($get('exercise_type_id') == 1))->hidden(fn(Callable $get) => ($get('exercise_type_id') !== 1))->reactive(),
]);
}
3 replies