Jia Yong Lim
Call actions in test
How do I call 'mutateFormDataBeforeFill' in test file?
Test:
EditTransaction.php:
Error:
it('can retrieve accurate edit data', function () {
$record = Transaction::first() ?? Transaction::factory()->create();
livewire(EditTransaction::class, [
'record' => $record->getRouteKey(),
])
->callAction('mutateFormDataBeforeFill', $record->toArray())
->assertFormSet($record->toArray());
});
it('can retrieve accurate edit data', function () {
$record = Transaction::first() ?? Transaction::factory()->create();
livewire(EditTransaction::class, [
'record' => $record->getRouteKey(),
])
->callAction('mutateFormDataBeforeFill', $record->toArray())
->assertFormSet($record->toArray());
});
protected function mutateFormDataBeforeFill(array $data): array
{
$restCust = RestaurantCustomer::find($data['restaurant_customer_id']);
$data['restaurant_id'] = $restCust->restaurant->name;
$data['customer_id'] = $restCust->user->name;
$data['point_id'] = Point::find($data['point_id'])->points;
return $data;
}
protected function mutateFormDataBeforeFill(array $data): array
{
$restCust = RestaurantCustomer::find($data['restaurant_customer_id']);
$data['restaurant_id'] = $restCust->restaurant->name;
$data['customer_id'] = $restCust->user->name;
$data['point_id'] = Point::find($data['point_id'])->points;
return $data;
}
FAILED Tests\Feature\Admin\ATransaction\EditTransactionTest > it can retrieve accurate edit data ArgumentCountError
Too few arguments to function App\Filament\Resources\TransactionResource\Pages\EditTransaction::mutateFormDataBeforeFill(), 0 passed in C:\Users\JiaYong\Documents\GitHub\food-partner\vendor\filament\actions\src\Concerns\InteractsWithActions.php on line 308 and exactly 1 expected
at app\Filament\Resources\TransactionResource\Pages\EditTransaction.php:23
19▕ Actions\DeleteAction::make(),
20▕ ];
21▕ }
22▕
➜ 23▕ protected function mutateFormDataBeforeFill(array $data): array
24▕ {
25▕ $restCust = RestaurantCustomer::find($data['restaurant_customer_id']);
26▕ $data['restaurant_id'] = $restCust->restaurant->name;
27▕ $data['customer_id'] = $restCust->user->name;
1 app\Filament\Resources\TransactionResource\Pages\EditTransaction.php:23
2 vendor\filament\actions\src\Concerns\InteractsWithActions.php:308
FAILED Tests\Feature\Admin\ATransaction\EditTransactionTest > it can retrieve accurate edit data ArgumentCountError
Too few arguments to function App\Filament\Resources\TransactionResource\Pages\EditTransaction::mutateFormDataBeforeFill(), 0 passed in C:\Users\JiaYong\Documents\GitHub\food-partner\vendor\filament\actions\src\Concerns\InteractsWithActions.php on line 308 and exactly 1 expected
at app\Filament\Resources\TransactionResource\Pages\EditTransaction.php:23
19▕ Actions\DeleteAction::make(),
20▕ ];
21▕ }
22▕
➜ 23▕ protected function mutateFormDataBeforeFill(array $data): array
24▕ {
25▕ $restCust = RestaurantCustomer::find($data['restaurant_customer_id']);
26▕ $data['restaurant_id'] = $restCust->restaurant->name;
27▕ $data['customer_id'] = $restCust->user->name;
1 app\Filament\Resources\TransactionResource\Pages\EditTransaction.php:23
2 vendor\filament\actions\src\Concerns\InteractsWithActions.php:308
2 replies
Reset Filter according to getEloquentQuery
Hi, I'm new to filament, I'm facing an issue on resetting filters, appreciate any help 😅
Expected behaviour:
Reset filter on index page and get it to query according to getEloquentQuery()
Current behaviour:
Clicking on reset button will reset everything and ignore queries in getEloquentQuery().
Code:
public static function getEloquentQuery(): Builder
{
$operation = last(explode('.', Route::currentRouteName()));
$query = parent::getEloquentQuery();
if ($operation == 'index')
{
$authUser = auth()->user();
if ($authUser->role == 'restaurant-admin') {
$rewardIds = Reward::where('restaurant_id', $authUser->restaurant_id)->pluck('id');
$query = $query->whereIn('reward_id', $rewardIds);
}
}
return $query
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
public static function getEloquentQuery(): Builder
{
$operation = last(explode('.', Route::currentRouteName()));
$query = parent::getEloquentQuery();
if ($operation == 'index')
{
$authUser = auth()->user();
if ($authUser->role == 'restaurant-admin') {
$rewardIds = Reward::where('restaurant_id', $authUser->restaurant_id)->pluck('id');
$query = $query->whereIn('reward_id', $rewardIds);
}
}
return $query
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
12 replies