cakan
cakan
FFilament
Created by cakan on 2/20/2024 in #❓┊help
Refresh repeater from child field
I have a Repeater that displays a list of documents. Each document is represented as a custom section with it's own delete button. But when I delete a record, repeater doesn't refresh. How do I refresh repeater from the child component? This is what I have tried but with no luck.
Repeater::make('documents')
->relationship()
->live()
->deletable(false)
->addable(false)
->registerListeners([
'refreshDocuments' => [
function (Repeater $component): void {
dd('test');
},
],
])
->schema([
Document::make('document_path')
->live()
->registerActions([
\Filament\Forms\Components\Actions\Action::make('deleteDocument')
->requiresConfirmation()
->action(function ($action, $record) {
$record->delete();
})
->after(fn ($livewire) => $livewire->dispatch('refreshDocuments'))
])
])
Repeater::make('documents')
->relationship()
->live()
->deletable(false)
->addable(false)
->registerListeners([
'refreshDocuments' => [
function (Repeater $component): void {
dd('test');
},
],
])
->schema([
Document::make('document_path')
->live()
->registerActions([
\Filament\Forms\Components\Actions\Action::make('deleteDocument')
->requiresConfirmation()
->action(function ($action, $record) {
$record->delete();
})
->after(fn ($livewire) => $livewire->dispatch('refreshDocuments'))
])
])
When I add new document, repeater refreshes. But when I delete it, it remains in the Repeater.
12 replies
FFilament
Created by cakan on 2/8/2024 in #❓┊help
DeleteAction throws error on custom header
I have created a custom header for my page and added this code to the header:
@if ($this->getHeaderActions())
<x-filament-tables::actions
:actions="$this->getHeaderActions()"
@class([
'shrink-0',
'sm:mt-7' => $this->getBreadcrumbs(),
])
/>
@endif
@if ($this->getHeaderActions())
<x-filament-tables::actions
:actions="$this->getHeaderActions()"
@class([
'shrink-0',
'sm:mt-7' => $this->getBreadcrumbs(),
])
/>
@endif
Code for my page looks like this:
class ViewCompany extends ViewRecord
{
protected static string $resource = CompanyResource::class;

public function getHeader(): ?View
{
return view('filament.custom.header');
}

protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
}
class ViewCompany extends ViewRecord
{
protected static string $resource = CompanyResource::class;

public function getHeader(): ?View
{
return view('filament.custom.header');
}

protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
}
What I want to achieve is to have Delete button on viewPage header. But I keep getting error saying "Filament\Actions\DeleteAction::Filament\Actions{closure}(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, null given, called in \vendor\filament\support\src\Concerns\EvaluatesClosures.php on line 35" If I put regular Action or EditAction instead of DeleteAction, it works as expected, What am I missing?
4 replies
FFilament
Created by cakan on 1/11/2024 in #❓┊help
Filament login using API
I want to use filament for my project without database. Instead, it will use external API to fetch the data. I know that I can use Sushi library to work with data models. What I don't know how to do is login user using external API. I've managed to make the login work with Sushi, but I can't use Filament::auth()->attempt(). I have extended authenticate method of Filament login page with this code:
$data = $this->form->getState();

$uri =config('service.api.url');
$res = Http::post($uri, $data)->json();

if (!isset($res['token_data']) && !isset($res['user'])) {
$this->throwFailureValidationException();
}

$user = new User();
$user->fill($res['user']);
Filament::auth()->setUser($user);

if (!$user->canAccessPanel(Filament::getCurrentPanel())) {
Filament::auth()->logout();
$this->throwFailureValidationException();
}

session()->regenerate();

return app(LoginResponse::class);
$data = $this->form->getState();

$uri =config('service.api.url');
$res = Http::post($uri, $data)->json();

if (!isset($res['token_data']) && !isset($res['user'])) {
$this->throwFailureValidationException();
}

$user = new User();
$user->fill($res['user']);
Filament::auth()->setUser($user);

if (!$user->canAccessPanel(Filament::getCurrentPanel())) {
Filament::auth()->logout();
$this->throwFailureValidationException();
}

session()->regenerate();

return app(LoginResponse::class);
This partially works but guards don't work any more. What is the correct way of doing this?
3 replies
FFilament
Created by cakan on 11/30/2023 in #❓┊help
TextEntry url
I have a custom page and it displays Infolist with some TextEntries. In my custom page I have this code:
public function fileViewInfolist(Infolist $infolist): Infolist
{
return $infolist
->record($this->company)
->schema([
TextEntry::make('files.path')
->label('')
->badge()
->color('secondary')
->url('files.path')
->openUrlInNewTab()
]);
}
public function fileViewInfolist(Infolist $infolist): Infolist
{
return $infolist
->record($this->company)
->schema([
TextEntry::make('files.path')
->label('')
->badge()
->color('secondary')
->url('files.path')
->openUrlInNewTab()
]);
}
So there is a company model which can have multiple files. This will display a list of all files. But I want to be able to have file name displayed to be clickable and link to a file. Issue is that in database (files.path) is stored only a filename. In order to have full url, I must do asset('storage/'. $filenameFromDB). How can I do that?
3 replies
FFilament
Created by cakan on 11/23/2023 in #❓┊help
Refresh tab badge
Is it possible to refresh a tab badge? I have Infolist which displays data in tabs. One of the tabs has a badge which displays number of users and a list of users. If I delete a user from the list, badge will still display old count of users. Is it possible to refresh the badge value or to somehow make it reactive? My tab is defined like this:
Tabs\Tab::make("Members")
->badge(fn(Company $record) => $record->users()->count())
->schema([
Pages\CompanyUsers::make('members')
]),
Tabs\Tab::make("Members")
->badge(fn(Company $record) => $record->users()->count())
->schema([
Pages\CompanyUsers::make('members')
]),
2 replies
FFilament
Created by cakan on 11/6/2023 in #❓┊help
Action not working in custom view
I have a custom page with action defined like this:
public function downloadBookAction(): Action
{
return Action::make('downloadBook')
->action(function (array $arguments) {
$this->book = Book::findOrFail($arguments['id']);
return Storage::disk('public')->download($this->book['file']);
});
}
public function downloadBookAction(): Action
{
return Action::make('downloadBook')
->action(function (array $arguments) {
$this->book = Book::findOrFail($arguments['id']);
return Storage::disk('public')->download($this->book['file']);
});
}
In blade for my custom view I have this line
{{ ($this->downloadBookAction)(['id'=>$book->id]) }}
{{ ($this->downloadBookAction)(['id'=>$book->id]) }}
This works as expected and clicking on a button starts file download. Later, on same custom page I have a modal dialog with Book details this modal uses another custom view:
View::make('bookDetails')->model(fn () => $this->book)->view('filament.resources.book-resource.pages.actions.book-details')
View::make('bookDetails')->model(fn () => $this->book)->view('filament.resources.book-resource.pages.actions.book-details')
But here the action defined in my custom page doesn't work. Code recognizes the downloadBookAction and the button is displayed with all formatting, icon, etc. but when I click on the button, nothing happens - it never gets into the ->action() method. What am I doing wrong?
2 replies
FFilament
Created by cakan on 10/26/2023 in #❓┊help
Widget with datepicker
I'm trying to make a widget that will be displayed on a Dashboard. Widget displays some statistics based on the selected date. I've created a Widget with a form and added form to the layout, but I'm having trouble how to get date from the form and pass it to my report function. This is my code:
class MonthlyReport extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = "filament.resources.user-resource.widgets.monthly-report";

public function getMonthlyReports(): array
{
return ActionHistoryHelper::getReport(Carbon::now()->format('Y-m-d'));
}

public function form(Form $form): Form
{
return $form->schema([DatePicker::make('date')]);
}
}
class MonthlyReport extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = "filament.resources.user-resource.widgets.monthly-report";

public function getMonthlyReports(): array
{
return ActionHistoryHelper::getReport(Carbon::now()->format('Y-m-d'));
}

public function form(Form $form): Form
{
return $form->schema([DatePicker::make('date')]);
}
}
View is just displaying the form and the data received from getMonthlyReports function. How do I pass the date value from form to the getMonthlyReports function and refresh the widget?
12 replies
FFilament
Created by cakan on 10/18/2023 in #❓┊help
Tabs with different content
Hello, I'm new to Filament and I'm stuck with organizing resources. I hope someone can point me into right direction. I have Company which has Users and Projects. I want to have one page that will have three tabs: - 1st tab will display company details, address, etc. - 2nd tab will display all users - 3rd tab will display all projects I created CompanyResource with following relations: public static function getRelations(): array { return [ ProjectsRelationManager::class, UsersRelationManager::class, ]; } This works as expected - I get two tabs displaying tables. How can I add 1st tab which will display company details? Am I on the right path when doing it with relations? Can relation point to infolist instead of table? Or should I work with tab some other way?
13 replies