d3v1anX
d3v1anX
FFilament
Created by d3v1anX on 8/20/2024 in #❓┊help
how to open edit modal from link?
hey guys, I implemented a filament table into a livewire component. On it there is a edit modal for each entry. Now I want to create a link on another page to this table, which opens the edit modal for an entry directly. I tried so many things like "&id=XXX" and checking in mount of livewire if request()->has('id') -> then try to "mountTableAction('edit', XXX)" but this will not work because Table is not initalized on mount. Then I tried to call with a direct link to "action=edit" like you can do with "action=create", but this won't work with integrating in livewire. Now I'm struggeling with some kind of Javascript to $wire.call('mountTableAction'...) but this also does not work and I think it surely can be easier.. 😄 Has anyone an idea how I can call the edit modal for a record after loading the table?
4 replies
FFilament
Created by d3v1anX on 8/9/2024 in #❓┊help
Open modal after page load
Hey guys, I have a table which has only modal (slideOver) to edit / create entries. Now I'd like to create a button from another resource to the target resource and open directly after loading the "create" modal. My code until now:
protected function getHeaderActions(): array
{
return [
Actions\Action::make('invite_user')
->label(__('Teammitglied einladen'))
->button()
->icon('heroicon-o-plus-circle')
->url(InvitationResource::getUrl('index', ['create' => true]))
,
];
}
protected function getHeaderActions(): array
{
return [
Actions\Action::make('invite_user')
->label(__('Teammitglied einladen'))
->button()
->icon('heroicon-o-plus-circle')
->url(InvitationResource::getUrl('index', ['create' => true]))
,
];
}
if I try to "create" instead of index it shows an error, because the route does not exists. -> its just a modal 🙂 Has anyone an idea? Maybe I can react on the parameter and open the modal somehow after loading the table?
4 replies
FFilament
Created by d3v1anX on 8/8/2024 in #❓┊help
Standard Create Action in modal
Hey guys, I want to get the standard action for creating an entry in a resource to get this into a modal. I already got this by removing the create route in getPages().
public static function getPages(): array
{
return [
'index' => Pages\ListInvitations::route('/'),
// 'create' => Pages\CreateInvitation::route('/create'),
'edit' => Pages\EditInvitation::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListInvitations::route('/'),
// 'create' => Pages\CreateInvitation::route('/create'),
'edit' => Pages\EditInvitation::route('/{record}/edit'),
];
}
Is this intended? Or is there a better way? The problem is now I don't know how to handle the record creation before saving.
8 replies
FFilament
Created by d3v1anX on 5/2/2024 in #❓┊help
Saving relationships on livewire Action
Hey guys, I have a strange situation. I created a livewire component with Filament-Actions. My action looks like this:
public function createAction(): Action
{
return CreateAction::make('create')
->label(__('Add page'))
->modalHeading(__('Add a new page'))
->modalDescription(__('bla'))
->modalSubmitActionLabel(__('Create'))

->form([
TextInput::make('name')
->label(__('Name'))
->required(),
Grid::make()
->schema([
Select::make('status')
->label(__('Status'))
->required()
->options([
0 => 'Hidden',
1 => 'Visible',
]),

Select::make('teams')
->label(__('Teams'))
->required()
->preload()
->multiple()
->searchable()
->relationship('teams', 'name'),
]),

RichEditor::make('content')
->label(__('Content'))
->required(),

Hidden::make('sort')
->default(fn () => Page::count() + 1),
])
->model(Page::class)
->action(
fn (Form $form) => dd($form->getState()) // Getting state - there is no teams relation
);
}
public function createAction(): Action
{
return CreateAction::make('create')
->label(__('Add page'))
->modalHeading(__('Add a new page'))
->modalDescription(__('bla'))
->modalSubmitActionLabel(__('Create'))

->form([
TextInput::make('name')
->label(__('Name'))
->required(),
Grid::make()
->schema([
Select::make('status')
->label(__('Status'))
->required()
->options([
0 => 'Hidden',
1 => 'Visible',
]),

Select::make('teams')
->label(__('Teams'))
->required()
->preload()
->multiple()
->searchable()
->relationship('teams', 'name'),
]),

RichEditor::make('content')
->label(__('Content'))
->required(),

Hidden::make('sort')
->default(fn () => Page::count() + 1),
])
->model(Page::class)
->action(
fn (Form $form) => dd($form->getState()) // Getting state - there is no teams relation
);
}
blade file:
<div>
{{ $this->createAction }}

<x-filament-actions::modals />
</div>
<div>
{{ $this->createAction }}

<x-filament-actions::modals />
</div>
Problem is, that the "teams" relationship will not be saved and is even not available at $form->getState() What am I missing? 😮
9 replies
FFilament
Created by d3v1anX on 2/20/2024 in #❓┊help
createOptionUsing on select not called in livewire component
Hey guys, I tried to add a form to a livewire component which works really well. Now I created a select field (Tag) with a relationship with the option to add a new Tag. I created "createOptionForm" on the select which is working fine and I wanted to include a logic, that it returns firstOrCreate on that creation. I added "createOptionUsing" as well, but unfortunately this method is not called somehow. I don't know why this is not working.. :/ Has someone an idea? My code:
class CreateProducts extends Component implements HasForms
{
use InteractsWithForms;

public ?array $data = [];

public function mount(): void
{
$this->form->fill();
}


public function form(Form $form): Form
{
return $form->schema([
Select::make('tag')
->createOptionForm(function () {
return [
TextInput::make('name')->label('Name')->required(),
];
})->createOptionUsing(function ($data) {
dd($data); // This is never called, instead the form is submitted and the Tag will be created.
})
->preload()
->relationship(name: 'tags', titleAttribute: 'name')
->multiple(),
])
->statePath('data')
->model(Product::class);
}

#[Layout('layouts.app')]
public function render(): View
{
return view('products.create-products');
}
class CreateProducts extends Component implements HasForms
{
use InteractsWithForms;

public ?array $data = [];

public function mount(): void
{
$this->form->fill();
}


public function form(Form $form): Form
{
return $form->schema([
Select::make('tag')
->createOptionForm(function () {
return [
TextInput::make('name')->label('Name')->required(),
];
})->createOptionUsing(function ($data) {
dd($data); // This is never called, instead the form is submitted and the Tag will be created.
})
->preload()
->relationship(name: 'tags', titleAttribute: 'name')
->multiple(),
])
->statePath('data')
->model(Product::class);
}

#[Layout('layouts.app')]
public function render(): View
{
return view('products.create-products');
}
blade:
<div>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Create product') }}
</h2>
</x-slot>
<div>
<div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">

<form wire:submit="create">
{{ $this->form }}
</form>

<x-filament-actions::modals />
</div>
</div>
</div>
<div>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Create product') }}
</h2>
</x-slot>
<div>
<div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">

<form wire:submit="create">
{{ $this->form }}
</form>

<x-filament-actions::modals />
</div>
</div>
</div>
9 replies
FFilament
Created by d3v1anX on 10/27/2023 in #❓┊help
Default sort direction based on defaultgroup in table builder
Hey guys, just wonder how I can use a defaultGroup in table builder with a default sort direction - is there no option?
return $table
->groups([
Group::make('start')->label('Start date (UTC)')->date(),
])
->defaultGroup('start') // how to set Desc as default? :D
return $table
->groups([
Group::make('start')->label('Start date (UTC)')->date(),
])
->defaultGroup('start') // how to set Desc as default? :D
thanks in advance!
5 replies
FFilament
Created by d3v1anX on 10/13/2023 in #❓┊help
Bug? Custom summarize with groups
Hi, I don't know if this is maybe a bug: I have the following table-code:
return $table
->groups([
Group::make('user.name'),
Group::make('start')->label('Start date (UTC)')->date(),
])
// [...]
->columns([
Tables\Columns\TextColumn::make('start')
->date()
->label('Start date (UTC)')
->icon('heroicon-o-calendar')
->sortable(query: function (Builder $query, string $direction) {
$query->orderBy('start', $direction);
}),
Tables\Columns\TextColumn::make('start_time')
->label('Start time (UTC)')
->getStateUsing(fn (Model $record) => $record->start)
->icon('heroicon-o-arrow-left-on-rectangle')

->time()
->sortable(query: function (Builder $query, string $direction) {
$query->orderByRaw('TIME(start) '.$direction);
}),
Tables\Columns\TextColumn::make('end')
->label('End time (UTC)')
->icon('heroicon-o-arrow-right-on-rectangle')
->time()
->sortable(query: function (Builder $query, string $direction) {
$query->orderByRaw('TIME(end) '.$direction);
}),
Tables\Columns\TextColumn::make('duration')
->state(fn (Model $record) => CarbonInterval::seconds($record->duration)->cascade()->format('%H:%I:%S'))
->sortable()
->icon('heroicon-o-clock')
->summarize(
Tables\Columns\Summarizers\Summarizer::make()->using(function ($query): string {
return DateService::fromSecondsToHours($query->sum('duration'));
})
),
)];
return $table
->groups([
Group::make('user.name'),
Group::make('start')->label('Start date (UTC)')->date(),
])
// [...]
->columns([
Tables\Columns\TextColumn::make('start')
->date()
->label('Start date (UTC)')
->icon('heroicon-o-calendar')
->sortable(query: function (Builder $query, string $direction) {
$query->orderBy('start', $direction);
}),
Tables\Columns\TextColumn::make('start_time')
->label('Start time (UTC)')
->getStateUsing(fn (Model $record) => $record->start)
->icon('heroicon-o-arrow-left-on-rectangle')

->time()
->sortable(query: function (Builder $query, string $direction) {
$query->orderByRaw('TIME(start) '.$direction);
}),
Tables\Columns\TextColumn::make('end')
->label('End time (UTC)')
->icon('heroicon-o-arrow-right-on-rectangle')
->time()
->sortable(query: function (Builder $query, string $direction) {
$query->orderByRaw('TIME(end) '.$direction);
}),
Tables\Columns\TextColumn::make('duration')
->state(fn (Model $record) => CarbonInterval::seconds($record->duration)->cascade()->format('%H:%I:%S'))
->sortable()
->icon('heroicon-o-clock')
->summarize(
Tables\Columns\Summarizers\Summarizer::make()->using(function ($query): string {
return DateService::fromSecondsToHours($query->sum('duration'));
})
),
)];
The summarize function works as expected on the buttom of the table. Unfortunately the group-summaries seems like there is something wrong. Already found: https://github.com/filamentphp/filament/issues/7578 but it seems already solved by @Dan Harrin - I don't know it this is related to it. Has anyone an idea? Or is it possible to customize the summarize-function just for the groups?
6 replies
FFilament
Created by d3v1anX on 10/10/2023 in #❓┊help
Widget Live form
Hey Guys, tried to add a form in a widget (with HasForms / InteractsWithForms) but unfortunately there is no live update on change. Is it not possible to do a live Form-Field?
<?php

namespace App\Filament\User\Widgets;

use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Widgets\Widget;

class Testwidget extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = 'filament.user.widgets.testwidget';

public function form(Form $form)
{
return $form->
schema([
TextInput::make('test')
->live()
->afterStateUpdated(fn () => dd('test')),
]);
}
}
<?php

namespace App\Filament\User\Widgets;

use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Widgets\Widget;

class Testwidget extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = 'filament.user.widgets.testwidget';

public function form(Form $form)
{
return $form->
schema([
TextInput::make('test')
->live()
->afterStateUpdated(fn () => dd('test')),
]);
}
}
B lade File:
<x-filament-widgets::widget>
<x-filament::section>
{{ $this->form }}
</x-filament::section>
</x-filament-widgets::widget>
<x-filament-widgets::widget>
<x-filament::section>
{{ $this->form }}
</x-filament::section>
</x-filament-widgets::widget>
5 replies
FFilament
Created by d3v1anX on 10/6/2023 in #❓┊help
if in x-filament component creating error
Hey guys, I don't know how to for my problem. I want to use a component of x-filament and try to add attributes based on an if statement. unfortunately it throws an error and I don't understand why? Could you have a look please? https://flareapp.io/share/Bm0Z0g67 If I remove the if statement it works fine.. 😮
2 replies
FFilament
Created by d3v1anX on 9/23/2023 in #❓┊help
Two TextColumns from same field
Hey guys, I tried to add two TextColumns from the same date field. One with only date, the other with the time. Looks like this:
Tables\Columns\TextColumn::make('start')
->label('Start date (UTC)')
->date()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('start')
->label('Start time (UTC)')
->time()
->sortable(),
Tables\Columns\TextColumn::make('start')
->label('Start date (UTC)')
->date()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('start')
->label('Start time (UTC)')
->time()
->sortable(),
there only the second field will be displayed. I tried to change the name and use state for displaying data - this will display both fields, but then it is not sortable / searchable, because the sort field is used from "make".
Tables\Columns\TextColumn::make('start date')
->state(fn (Model $record) => $record->start)
->label('Start date (UTC)')
->date()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('start')
->label('Start time (UTC)')
->time()
->sortable(),
Tables\Columns\TextColumn::make('start date')
->state(fn (Model $record) => $record->start)
->label('Start date (UTC)')
->date()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('start')
->label('Start time (UTC)')
->time()
->sortable(),
Is my approach to display two fields of one column correct? Or am I missing something? 🙂 Thank you very much!
4 replies
FFilament
Created by d3v1anX on 8/22/2023 in #❓┊help
dynamic navigation item in panel
Hey there, i tried to create a dynamic navigation items:
public function panel(Panel $panel): Panel
{
return $panel
//...
->navigationItems($this->getNavigationItems());
}

private function getNavigationItems()
{
if (\auth()->user()->canAccessPanel(Filament::getPanel('admin'))) {
return [
NavigationItem::make(fn () => __('Login as admin'))
->url('/admin')
->icon('heroicon-o-arrow-right-on-rectangle')
->visible(fn () => auth()->user()->canAccessPanel(Filament::getPanel('admin')))
->group('Administration')
->sort(2),
];
} else {
return [];
}
}
public function panel(Panel $panel): Panel
{
return $panel
//...
->navigationItems($this->getNavigationItems());
}

private function getNavigationItems()
{
if (\auth()->user()->canAccessPanel(Filament::getPanel('admin'))) {
return [
NavigationItem::make(fn () => __('Login as admin'))
->url('/admin')
->icon('heroicon-o-arrow-right-on-rectangle')
->visible(fn () => auth()->user()->canAccessPanel(Filament::getPanel('admin')))
->group('Administration')
->sort(2),
];
} else {
return [];
}
}
The error
Target class [hash] does not exist.
Target class [hash] does not exist.
came up and I don't know where to add the Hash-Class? Can someone help me out? Thank you 🙂
12 replies
FFilament
Created by d3v1anX on 8/9/2023 in #❓┊help
Access panel name globally or in scopes
Hey there, is it possible to access the actual panel globally somehow, or in a global scope? I want to add a global scope if I'm not on the admin panel
public function apply(Builder $builder, Model $model): void
{
// if(
!\Auth::user() || // for console commands
(
\Auth::user()->isSuperAdmin() // &&
// $panel->name == "admin" // <<<--- Somehow here
)
)
return;

$builder->whereHas('user', function (Builder $query) {
$query->where('company_id', \Auth::user()->company_id);
});

}
public function apply(Builder $builder, Model $model): void
{
// if(
!\Auth::user() || // for console commands
(
\Auth::user()->isSuperAdmin() // &&
// $panel->name == "admin" // <<<--- Somehow here
)
)
return;

$builder->whereHas('user', function (Builder $query) {
$query->where('company_id', \Auth::user()->company_id);
});

}
5 replies
FFilament
Created by d3v1anX on 8/2/2023 in #❓┊help
possible to highlight table search term in results?
3 replies
FFilament
Created by d3v1anX on 7/31/2023 in #❓┊help
NavigationItem group is visible even if no item is visible
Hey there, according to https://beta.filamentphp.com/docs/3.x/panels/navigation#registering-custom-navigation-items the group is visible, even if the conditionally hide is true for all items. Is there any chance to hide the group as well?
use Filament\Navigation\NavigationItem;
use Filament\Panel;

public function panel(Panel $panel): Panel
{
return $panel
// ...
->navigationItems([
NavigationItem::make('Analytics')
->url('https://filament.pirsch.io', shouldOpenInNewTab: true)
->icon('heroicon-o-presentation-chart-line')
->group('Reports')
->sort(3)
->visible(false),
// ...
]);
}
use Filament\Navigation\NavigationItem;
use Filament\Panel;

public function panel(Panel $panel): Panel
{
return $panel
// ...
->navigationItems([
NavigationItem::make('Analytics')
->url('https://filament.pirsch.io', shouldOpenInNewTab: true)
->icon('heroicon-o-presentation-chart-line')
->group('Reports')
->sort(3)
->visible(false),
// ...
]);
}
4 replies
FFilament
Created by d3v1anX on 7/30/2023 in #❓┊help
Tailwind colors does not appear with vite
I am on beta21 and I added a custom button. Wanted to change the color to tailwinds "bg-gray-500" - unfortunately even with vite it will not render. Is there something I miss?
5 replies
FFilament
Created by d3v1anX on 7/28/2023 in #❓┊help
Add livewire-script in Topbar
Is it possible to add a livewire script inside of the topbar without publishing views?
3 replies