Prosp30
Tenant users - hide certain statuses from the menu
I am trying to show tenant users and their teams in two areas of my app.
One is a filament resource page called Users, a table view with users in the current tenant that have the following status in team_user table: A, B
Code for it
Users.php
public function teams(): BelongsToMany
{
return $this->belongsToMany(Team::class)->withTimestamps()->withPivot('team_id', 'user_id', 'status', 'created_at', 'updated_at')->where('team_user.status', '<>', 'B');
}
public function team() {
return Filament::getTenant();
}
Also, on the resource page for Users
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->with('teams');
//return parent::getEloquentQuery()->where('team_user.status', 'A')->with('teams');
}
The problem that I am facing is the following. In the table, users for the tenant are displayed correctly (show me all users that are in status A or I, don't show users in status B. That works fine. On the tenancy menu (top left on the navbar), the user should see the tenant only if the user is in status A. Right now the user can see the tenant even when in status I.
How to make different logic for these two segments of the app, in other words, how to control tenancy menu, when to show the tenant and when not to show it? It is directly connected to teams() relationship on the User model, so changing it there affects both the resource page and the tenancy menu.4 replies
Download PDF using Spatie Laravel-PDF on table action
I am trying to download a PDF generated from a blade view. I tried DOMPDF and it works fine, but I would like to use Spatie's PDF which has better funcionality. I added the PDF to the table action, but the button just spins and nothing gets returned. Is there a way to convert the PDF to a stream to make it downloadable or?
Action::make('download')
->action(function (Invoice $record)
{
return pdf()->view('pdf.invoice', ['invoice' => $record])
->format('a4')
->name('your-invoice.pdf')
->download();
})
->iconButton('heroicon-o-document-arrow-down')
->icon('heroicon-o-document-arrow-down')
->label('Preuzmi PDF'),
23 replies
Custom text format
Hi there, I am wondering, how could I achieve the following with Filament?
Let's say I have a text that is made of: User ID / Resource ID / Counter
Ie: 500 / 1234 / 1
And the order of the fields can be customizable, ie it can be for some Resource ID / Counter / User ID
Is there a way to preformat text with Filament by using the fields and a pattern or I shouldn't look into Filament for this part?
4 replies
Update pivot table when editing record
Hi there,
I am trying to update a pivot table record while editing the main record.
I have the following table
team_user
user_id
team_id
operator_id (just a string value I wish to update)
On both user and team I have belongsToMany (M:M relationship).
This is how I fetch the operator_id in the table, using the team_user pivot table
TextColumn::make('operator_id')->label('Oznaka operatera')->sortable()->searchable()
->state(function (User $record): string {
return $record->getUserInTeam()->first()->pivot->operator_id;
}),
How can I acomplish the same so when the record is created, operator_id is filled from the form and when the record is being edited, operator ID gets displayed and can be edited?3 replies
RichText image upload on private disk
Hi there,
I am trying to find a way on how to display images in the RichText editor that are private (ie. only viewable by the user that created the note). Using the public disk works, but as soon as I use private disk it fails to fetch the image (404).
Section::make()->columns(1)
->schema([
RichEditor::make('notes')->label('Bilješke')
->fileAttachmentsDisk('private')
->fileAttachmentsDirectory('form-attachments')
->fileAttachmentsVisibility('private')
])]);
filesystems.php
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'url' => env('APP_URL').'/private',
'visibility' => 'private',
],
12 replies
Reset password email locale
Hello,
I am using non-english locale for my app. Everything is translated okay pretty much, except for the reset password notification and emails. Where should I look to overwrite these values, both in the notification and in the email itself? I tried setting up my custom email message and I can change the greetings, salute, line and action, but there's no way to change the footer where it says to copy and paste the link into the browser.
Ie: We have emailed your password reset link.
6 replies
Changing default Save button and Create Another labels?
Hello there. I started learning Filament and I am building a small demo app to get a hang of it. I am loving it so far, had a few issues but managed to solve it. Only issue that I'm facing right now is how to change default action button labels, on the CreateRecord resource. I haven't found it in the docs (or I searched the wrong terms).
Also, should I open an issue, because Croatian language translation is a bit off (not really in the spirit of the language).
Actions are labeled:
1) Save - Napravi (literal translation would be Do it which sounds off) - more correct one would be Spremi
2) Save & Another - Napravi i napravi novi (sound off like in first point) - correct one would be Spremi i novi
Thanks and apologies if it's a newbie question 🙂
6 replies