oliverbusk
oliverbusk
Explore posts from servers
FFilament
Created by oliverbusk on 10/21/2024 in #❓┊help
Removing the per page summarization
No description
2 replies
FFilament
Created by oliverbusk on 10/18/2024 in #❓┊help
Filament Table Text Column action not firing
I have a Filament table widget, in which I do a semi complex query to fetch some grouped data:
public function table(Table $table): Table
{
return $table
->query(
$this->sql()
)
->striped()
->heading('Missing Co-Loader')
->columns([
TextColumn::make('job_operator_name')->label('Job Operator Name'),
TextColumn::make('num_jobs')->label('Total Jobs')->alignCenter()->action(
ViewAction::make('test')
->modalContent(fn (Model $model): View => view(
'filament.app.widgets.pegasus.commercial.top-stats-widget',
[
'model' => $model,
],
))
)
]);
}

protected function sql()
{
return ReportShipment::query()
->select(
DB::raw('ROW_NUMBER() OVER (ORDER BY COUNT(id) DESC) as id'),
'job_operator_name',
DB::raw('COUNT(id) as num_jobs')
)
->where('consol_type', 'CLD')
->whereNull('consol_co_loaded_with_code')
->groupBy('job_operator_name')
->orderByDesc('num_jobs');

}

public function getTableRecordKey($record): string
{
$name = str_replace(' ', '_', $record->job_operator_name);
return 'missing_co_loader_widget_'.$name;
}
public function table(Table $table): Table
{
return $table
->query(
$this->sql()
)
->striped()
->heading('Missing Co-Loader')
->columns([
TextColumn::make('job_operator_name')->label('Job Operator Name'),
TextColumn::make('num_jobs')->label('Total Jobs')->alignCenter()->action(
ViewAction::make('test')
->modalContent(fn (Model $model): View => view(
'filament.app.widgets.pegasus.commercial.top-stats-widget',
[
'model' => $model,
],
))
)
]);
}

protected function sql()
{
return ReportShipment::query()
->select(
DB::raw('ROW_NUMBER() OVER (ORDER BY COUNT(id) DESC) as id'),
'job_operator_name',
DB::raw('COUNT(id) as num_jobs')
)
->where('consol_type', 'CLD')
->whereNull('consol_co_loaded_with_code')
->groupBy('job_operator_name')
->orderByDesc('num_jobs');

}

public function getTableRecordKey($record): string
{
$name = str_replace(' ', '_', $record->job_operator_name);
return 'missing_co_loader_widget_'.$name;
}
This will yield a table like this:
|Job Operator Name| Total Jobs |
--------------------------------
|Name A | 5 |
|Name B | 15 |
...
|Job Operator Name| Total Jobs |
--------------------------------
|Name A | 5 |
|Name B | 15 |
...
And the number in the Total Jobs column will be clickable. However, when I click the number, nothing happens. If I check the console -> network requests, I see that an update request is indeed sent, but still - nothing happens. I would expect the action to open a modal, with the content from my custom blade view. What am I doing wrong?
2 replies
FFilament
Created by oliverbusk on 8/27/2024 in #❓┊help
Grouped row in Filament together with action
I have the following table in Filament:
public function getIncentiveRequests(): Builder
{
return OIPRequest::query()
->selectRaw('
ROW_NUMBER() OVER (ORDER BY branch_id, department_id, business_type, expire_at) as id,
branch_id,
department_id,
business_type,
expire_at,
GROUP_CONCAT(id SEPARATOR \',\') as original_ids
')
->where('status', 'approved')
->where('branch_id', 1) // Adjust this as needed
->where('expire_at', '>', '2024-08-01')
->groupBy('branch_id', 'department_id', 'business_type', 'expire_at');
}

public function table(Table $table): Table
{
return $table
->query(function (): Builder {
return $this->getIncentiveRequests();
})
->modifyQueryUsing($this->modifyQueryWithActiveTab(...))
->columns([
TextColumn::make('department.name')
->label('Department')
->sortable(),
TextColumn::make('gp')
->label('GP')
->money('eur', true)
->state(function ($record) {
return $this->calculateGP($record);
})
->sortable()
])
->actions([
ActionGroup::make([
Action::make('Links')->action(fn (OIPRequest $record) => dd($record))
])
])
}
public function getIncentiveRequests(): Builder
{
return OIPRequest::query()
->selectRaw('
ROW_NUMBER() OVER (ORDER BY branch_id, department_id, business_type, expire_at) as id,
branch_id,
department_id,
business_type,
expire_at,
GROUP_CONCAT(id SEPARATOR \',\') as original_ids
')
->where('status', 'approved')
->where('branch_id', 1) // Adjust this as needed
->where('expire_at', '>', '2024-08-01')
->groupBy('branch_id', 'department_id', 'business_type', 'expire_at');
}

public function table(Table $table): Table
{
return $table
->query(function (): Builder {
return $this->getIncentiveRequests();
})
->modifyQueryUsing($this->modifyQueryWithActiveTab(...))
->columns([
TextColumn::make('department.name')
->label('Department')
->sortable(),
TextColumn::make('gp')
->label('GP')
->money('eur', true)
->state(function ($record) {
return $this->calculateGP($record);
})
->sortable()
])
->actions([
ActionGroup::make([
Action::make('Links')->action(fn (OIPRequest $record) => dd($record))
])
])
}
If I dump the $record from the text column's state function, it successfully returns all the original_ids from my query comma seperated (2,4,5). However, if I dump the $record from the action, it only takes the first one: original_ids => 2 How can I get all the original_ids in the action for my grouped record?
2 replies
FFilament
Created by oliverbusk on 8/19/2024 in #❓┊help
Table actions not firing
I have a table function in a custom Filament page: I have initialized the page like this:
<?php

//...
use Filament\Tables\Actions\Action;
//...

class IncentiveOverview extends Page implements HasTable, HasForms, HasActions
{
use InteractsWithTable;
use InteractsWithForms;
use InteractsWithActions;
use HasTabs;
<?php

//...
use Filament\Tables\Actions\Action;
//...

class IncentiveOverview extends Page implements HasTable, HasForms, HasActions
{
use InteractsWithTable;
use InteractsWithForms;
use InteractsWithActions;
use HasTabs;
Table:
public function table(Table $table): Table
{
return $table
->query(function (): Builder {
return $this->getIncentiveRequests()->groupBy(['branch_id', 'department_id']);
})
->modifyQueryUsing($this->modifyQueryWithActiveTab(...))
->columns([
TextColumn::make('department.name')
->label('Department')
->sortable(),
])
->actions([
Action::make('view_incentive_details')
->label('View Incentive Details')
->action(function ($record) {
dd($record);
})
]);
}
public function table(Table $table): Table
{
return $table
->query(function (): Builder {
return $this->getIncentiveRequests()->groupBy(['branch_id', 'department_id']);
})
->modifyQueryUsing($this->modifyQueryWithActiveTab(...))
->columns([
TextColumn::make('department.name')
->label('Department')
->sortable(),
])
->actions([
Action::make('view_incentive_details')
->label('View Incentive Details')
->action(function ($record) {
dd($record);
})
]);
}
Then, the blade view is looking like this:
<x-filament::page>
<div class="flex flex-col gap-4">
<x-filament-panels::resources.tabs />
<div class="relative">
{{ $this->table }}
</div>
<x-filament-actions::modals />
</div>
</x-filament::page>
<x-filament::page>
<div class="flex flex-col gap-4">
<x-filament-panels::resources.tabs />
<div class="relative">
{{ $this->table }}
</div>
<x-filament-actions::modals />
</div>
</x-filament::page>
When I try to trigger the view_incentive_details, I would for now, expect that it would just dd the $record, however, when I click it, a spinner is just shown briefly: !image
7 replies
FFilament
Created by oliverbusk on 1/12/2024 in #❓┊help
Conditionally hiding the sidebar on specific pages/resources
Hi. Is it possible to conditionally collapse the sidebar on specific pages? I have a few pages where the main content is very dense, so I would like to have the extra screen real estate.
4 replies
FFilament
Created by oliverbusk on 1/12/2024 in #❓┊help
Conditionally hide a section
Hi. Is it possible to conditionally hide a Section, based on another value on the form? E.g.:
//...

Forms\Components\Section::make('Options')
->schema([
Forms\Components\Toggle::make('receiveable')
->required(),
])
// Conditional Section for 'receivable'
Forms\Components\Section::make('Receivable Details')
->schema([
// Fields goes here...
])->hidden(fn ($get): bool => $get('receiveable') == false)
//...

Forms\Components\Section::make('Options')
->schema([
Forms\Components\Toggle::make('receiveable')
->required(),
])
// Conditional Section for 'receivable'
Forms\Components\Section::make('Receivable Details')
->schema([
// Fields goes here...
])->hidden(fn ($get): bool => $get('receiveable') == false)
The section Receivable Details is hidden on page load, but I want to show/hide it based on the toggle value from receivable
2 replies
FFilament
Created by oliverbusk on 1/10/2024 in #❓┊help
Tenant with an extra layer of ownership - uploading documents
Hi. I have set up Filament with multitenancy, and I am using a classic "Team" model. I have one more layer below a team, that I call buckets: A team can have many buckets, and a bucket can belong to one team. Then, under a bucket, the user can upload many documents, meaning that: a bucket can have many documents, and a document can belong to one bucket. Now, I have set up a new resource called DocumentResource, but I am simply unable to figure out how I can upload a simple document via a header action, since the document should belong to a bucket, and not to a team directly. In my App panel, I have specified this:
tenant(Team::class, ownershipRelationship: 'bucket')
tenant(Team::class, ownershipRelationship: 'bucket')
Then, on the DocumentResource I have set a relationship:
protected static ?string $model = Document::class;
protected static ?string $tenantRelationshipName = 'buckets';
protected static ?string $model = Document::class;
protected static ?string $tenantRelationshipName = 'buckets';
Then, under the ListDocuments page, I would like to have the "Upload Document" modal:
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->form([
FileUpload::make('name')
->required()
->storeFileNamesIn('original_filename')
])
];
}
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->form([
FileUpload::make('name')
->required()
->storeFileNamesIn('original_filename')
])
];
}
When I upload, it fails, since Filament is looking for a team_id on the documents table. But there is none, only a bucket_id
9 replies
FFilament
Created by oliverbusk on 1/10/2024 in #❓┊help
Any route in web.php gives 404
I would like to add a simple route in my Filament app like below:
Route::get('/test', function () {
dd("Here");
});
Route::get('/test', function () {
dd("Here");
});
When I access the /test url, Laravel throws an 404 Not Found. What am I doing wrong?
6 replies
FFilament
Created by oliverbusk on 1/9/2024 in #❓┊help
Redirect to new slug after updating tenant name
Hi. I have the below EditTenantProfile set up just like the docs:
//EditTeamProfile.php
class EditTeamProfile extends EditTenantProfile
{
public static function getLabel(): string
{
return 'Team profile';
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name'),
// ...
]);
}
}
//EditTeamProfile.php
class EditTeamProfile extends EditTenantProfile
{
public static function getLabel(): string
{
return 'Team profile';
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name'),
// ...
]);
}
}
Now, I have a slug column on my Team model, that is automatically set based on the name:
//Team.php
public static function boot()
{
parent::boot();

static::saving(function ($model) {
$model->slug = Str::of($model->name)->slug('-');
});
}
//Team.php
public static function boot()
{
parent::boot();

static::saving(function ($model) {
$model->slug = Str::of($model->name)->slug('-');
});
}
Now, currently, when updating the name of the team, it will result in a 404 page (since the slug is now updated, and thus the old slug no longer exists). I added this method on the EditTeamProfile.php, but I am unsure if there are other easier ways of doing this?
protected function getRedirectUrl(): ?string
{
//Update as the slug will be different
return route('filament.app.tenant.profile', ['tenant' => $this->tenant->slug]);
}
protected function getRedirectUrl(): ?string
{
//Update as the slug will be different
return route('filament.app.tenant.profile', ['tenant' => $this->tenant->slug]);
}
2 replies
FFilament
Created by oliverbusk on 8/10/2023 in #❓┊help
Route [filament.app.auth.logout] not defined.
Hi. I am trying to configure the main path for a panel I have created as described here: https://filamentphp.com/docs/3.x/panels/configuration#changing-the-path. It should be accessible from "/" instead of "/app":
return $panel
->id('app')
->path('/')
//...
return $panel
->id('app')
->path('/')
//...
However, this gives me the following error:
Route [filament.app.auth.logout] not defined.
Please see the stacktrace: https://flareapp.io/share/oPR0y9K5
4 replies
FFilament
Created by oliverbusk on 8/10/2023 in #❓┊help
Filament for non-admin pages
Hi all. Loving Filament so far - it is an awesome tool to build backend/admin pages. I am wondering if I can use it to build an entire app - so also the pages that my logged in users uses?
10 replies