Bonux
Bonux
FFilament
Created by Bonux on 4/8/2024 in #❓┊help
Using Import action in Wizard and creating import action records for a relational record
First of all, is it possible to add import action to steps?
protected function getSteps(): array
{
return [
Step::make('Job settings')
->schema([
Select::make('job_type')
->searchable()
->live()
->options([
'foo' => 'foo',
'bar' => 'bar',
])
]),
Step::make('Importing file')
->schema([
ImportAction::make()->importer(
// Based on job_type switch out the importer
// Could be done with match() {} if I was able to pass a callback function and get the Get $get('job_type')
)
]),
];
}
protected function getSteps(): array
{
return [
Step::make('Job settings')
->schema([
Select::make('job_type')
->searchable()
->live()
->options([
'foo' => 'foo',
'bar' => 'bar',
])
]),
Step::make('Importing file')
->schema([
ImportAction::make()->importer(
// Based on job_type switch out the importer
// Could be done with match() {} if I was able to pass a callback function and get the Get $get('job_type')
)
]),
];
}
Secondly it is possible to make the importer import data to a belongsTo relation? A Process model is made from the step wizard and Process model hasMany ProcessableRows which are improted by the ImportAction importer. I need to somehow pass Process model id to the importer action
public function resolveRecord(): ?ProcessableRows
{
????
return ProcessableRows::create([
'process_id' => $process->id
]);
}
public function resolveRecord(): ?ProcessableRows
{
????
return ProcessableRows::create([
'process_id' => $process->id
]);
}
3 replies
FFilament
Created by Bonux on 1/18/2024 in #❓┊help
How to remove primary key order from the eloquent query.
I am making a custom table for my client and grouping the results based on my needs.
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->select(
'destination_pattern',
DB::raw('COUNT(*) as total_requests'),
DB::raw('SUM(CASE WHEN duration > 1 THEN 1 ELSE 0 END) as count_duration_gt_1s'),
DB::raw('SUM(CASE WHEN duration > 5 THEN 1 ELSE 0 END) as count_duration_gt_5s'),
DB::raw('SUM(CASE WHEN duration > 10 THEN 1 ELSE 0 END) as count_duration_gt_10s')
)
->groupBy('destination_pattern')
->orderBy('total_requests', 'DESC');
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->select(
'destination_pattern',
DB::raw('COUNT(*) as total_requests'),
DB::raw('SUM(CASE WHEN duration > 1 THEN 1 ELSE 0 END) as count_duration_gt_1s'),
DB::raw('SUM(CASE WHEN duration > 5 THEN 1 ELSE 0 END) as count_duration_gt_5s'),
DB::raw('SUM(CASE WHEN duration > 10 THEN 1 ELSE 0 END) as count_duration_gt_10s')
)
->groupBy('destination_pattern')
->orderBy('total_requests', 'DESC');
}
Seems like the Filament automatically adds primary key ordering to the query which then causes an sql exception.
ORDER BY
`total_requests` DESC,
`monitors`.`id` ASC
ORDER BY
`total_requests` DESC,
`monitors`.`id` ASC
Is there a way to remove the default key order by from the query? Whole query:
SELECT
`destination_pattern`,
COUNT(*) AS total_requests,
SUM(
CASE
WHEN duration > 1 THEN 1
ELSE 0
END
) AS count_duration_gt_1s,
SUM(
CASE
WHEN duration > 5 THEN 1
ELSE 0
END
) AS count_duration_gt_5s,
SUM(
CASE
WHEN duration > 10 THEN 1
ELSE 0
END
) AS count_duration_gt_10s
FROM
`monitors`
GROUP BY
`destination_pattern`
ORDER BY
`total_requests` DESC,
`monitors`.`id` ASC
limit
10 OFFSET 0
SELECT
`destination_pattern`,
COUNT(*) AS total_requests,
SUM(
CASE
WHEN duration > 1 THEN 1
ELSE 0
END
) AS count_duration_gt_1s,
SUM(
CASE
WHEN duration > 5 THEN 1
ELSE 0
END
) AS count_duration_gt_5s,
SUM(
CASE
WHEN duration > 10 THEN 1
ELSE 0
END
) AS count_duration_gt_10s
FROM
`monitors`
GROUP BY
`destination_pattern`
ORDER BY
`total_requests` DESC,
`monitors`.`id` ASC
limit
10 OFFSET 0
4 replies