setiawanh
setiawanh
FFilament
Created by setiawanh on 5/7/2024 in #❓┊help
Can Custom Filter Form performs filter through joins?
I build a filament table with an aim to LEFT JOIN 2 tables: "Employees" and "Attendances". The SQL that I am trying to build is as follow:
select * from `employees` left join `attendances` on (`employees`.`id` = `attendances`.`employee_id` AND attendances.dt_attendance = '<filter dt value>') where `employees`.`deleted_at` is null order by `employees`.`id` asc;
select * from `employees` left join `attendances` on (`employees`.`id` = `attendances`.`employee_id` AND attendances.dt_attendance = '<filter dt value>') where `employees`.`deleted_at` is null order by `employees`.`id` asc;
This is the table code snippet that I have with the custom filter form:
$table
->query(Employee::query())
->columns([
TextColumn::make('first_name'),
TextColumn::make('result'),
])
->filters([
Filter::make('dt_attendance')
->form([
Forms\Components\DatePicker::make('dt')->default(date("Y-m-d"))->label('Tanggal')
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['dt'],
fn (Builder $query, $date): Builder => $query->leftJoin('attendances', function($join) use ($date)
{
$join->on('attendances.employee_id', '=', 'employees.id');
$join->on('attendances.dt_attendance','>=',DB::raw("'".$date."'"));
})
);
})
], layout: FiltersLayout::AboveContent)
$table
->query(Employee::query())
->columns([
TextColumn::make('first_name'),
TextColumn::make('result'),
])
->filters([
Filter::make('dt_attendance')
->form([
Forms\Components\DatePicker::make('dt')->default(date("Y-m-d"))->label('Tanggal')
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['dt'],
fn (Builder $query, $date): Builder => $query->leftJoin('attendances', function($join) use ($date)
{
$join->on('attendances.employee_id', '=', 'employees.id');
$join->on('attendances.dt_attendance','>=',DB::raw("'".$date."'"));
})
);
})
], layout: FiltersLayout::AboveContent)
When I checked on laravel debugbar, somehow the query log is not showing the joins when I put the joins in the "filter query". However, when I moved the joins, in the "table query", it is executing it correctly. Thus, is it possible to create joins in "filter query"?
3 replies
FFilament
Created by setiawanh on 5/7/2024 in #❓┊help
Custom Filament Table with Query of Left Joined Tables
I have managed to create livewire component with filament table in it as described here: https://filamentphp.com/docs/3.x/tables/adding-a-table-to-a-livewire-component In the example, the query for the table is given for a single model. (Product::query()) How can I pass the query for the filament table so that it will take 2 joined tables? SELECT * FROM employees LEFT JOIN attendances ON employees.id = attendances.employee_id
15 replies
FFilament
Created by setiawanh on 5/4/2024 in #❓┊help
Action button in View Resource to Show Create Popup based on Relationship Manager
I have an Employee resource with work_histories in relationship manager. I want to have an action button in the View Employee Resource which when click, will open the popup that is similar to the form for creating new work history in the relationship manager. What should I put in the URL / function when I create Action::make() ? Thanks!
8 replies