torriv
torriv
FFilament
Created by torriv on 10/30/2023 in #❓┊help
showing headerActions based on what tab you are on
I'm trying to show a header action only if you are not on the 'all' tab. when i output $livewire->activeTab in ray(), it updates correctly. so i figured out this behaviour: 1. if i go to the page and try different tabs, nothing happens. 2. if i click on a tab that is not 'all', and then refresh the page, then it works as expected when i click back and forth on different tabs. anyone knows why and how to fix it?
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('packingList.name')->label('Liste'),
TextColumn::make('item')->label('Hva'),
TextColumn::make('quantity')->label('Antall'),
ToggleColumn::make('is_packed')->label('Pakket?'),
])
->headerActions([
Tables\Actions\CreateAction::make()->hidden(function (Livewire $livewire)
{
ray($livewire->activeTab);
return $livewire->activeTab === 'all';
}),
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('packingList.name')->label('Liste'),
TextColumn::make('item')->label('Hva'),
TextColumn::make('quantity')->label('Antall'),
ToggleColumn::make('is_packed')->label('Pakket?'),
])
->headerActions([
Tables\Actions\CreateAction::make()->hidden(function (Livewire $livewire)
{
ray($livewire->activeTab);
return $livewire->activeTab === 'all';
}),
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
3 replies
FFilament
Created by torriv on 10/21/2023 in #❓┊help
Add styles to tailwind
I've come across an scenario where i need to use this from tailwind: bg-red-600, bg-cyan-600 and bg-green-500, i have read the docs, but not sure if i understand what needs to be done to be able to use these... they are going to be used in a custom view.
47 replies
FFilament
Created by torriv on 10/12/2023 in #❓┊help
Possible to extract common fields?
Just wondering if i'm doing it right, or if there is a way to optimize it somehow. I feel it's a lot of repeating. any suggestions are welcome. i have a form where i put each day in a week in a tab. so the tabs are named 'Monday', 'Tuesday' and so on. Under each of these tabs, i'm adding data for that day.

Tabs\Tab::make('Mandag')
->badge(fn($record) => WeekplanExercise::where('day', 1)->where('weekplan_id', $record?->id)->count())
->schema([
Repeater::make('exercises_1')
->relationship('weekplanExercises', function ($query) {
$query->where('day', 1);
})
->label('Økter')
->schema([
Hidden::make('day')->default('1'),
Select::make('exercise_id')
//more code
Select::make('training_program_id')
//more code
TimePicker::make('start_time')
//more code
TimePicker::make('end_time')
//more code
Select::make('intensity')->options([
'green' => 'Lett',
'darkcyan' => 'Vedlikehold',
'crimson' => 'Tung',
])
->label('Hvor tung?')
->required(),
])
->defaultItems(0)
->grid(4)
->itemLabel(
fn(array $state): ?string => Exercise::all()->where('id',
$state['exercise_id'])->first()?->name
)
->addActionLabel('Legg til økt')
->collapsible(),
]),

Tabs\Tab::make('Mandag')
->badge(fn($record) => WeekplanExercise::where('day', 1)->where('weekplan_id', $record?->id)->count())
->schema([
Repeater::make('exercises_1')
->relationship('weekplanExercises', function ($query) {
$query->where('day', 1);
})
->label('Økter')
->schema([
Hidden::make('day')->default('1'),
Select::make('exercise_id')
//more code
Select::make('training_program_id')
//more code
TimePicker::make('start_time')
//more code
TimePicker::make('end_time')
//more code
Select::make('intensity')->options([
'green' => 'Lett',
'darkcyan' => 'Vedlikehold',
'crimson' => 'Tung',
])
->label('Hvor tung?')
->required(),
])
->defaultItems(0)
->grid(4)
->itemLabel(
fn(array $state): ?string => Exercise::all()->where('id',
$state['exercise_id'])->first()?->name
)
->addActionLabel('Legg til økt')
->collapsible(),
]),
This code is the same for each day, except the tab name, badge, repeater make() and relationship query. Would it be possible to extract the common parts of this somehow? hope you understand what i'm asking for.
6 replies
FFilament
Created by torriv on 10/11/2023 in #❓┊help
Adding livewire component to custom page
I have a custom page where i'm showing a table. The table is in different livewire components. for example the header is in one components and the rows are in another component. it's working fine locally. But as soon as i deploy it, i get
Unable to find component: [landslag.weekplan.table-header]
Unable to find component: [landslag.weekplan.table-header]
in my page i have this code:
<x-filament-panels::page>
<div class="overflow-y-auto overflow-x-auto">
<table class="w-full min-w-full dark:bg-gray-800 text-white dark:border-gray-700 rounded-xl">

@livewire('landslag.weekplan.table-header')

//Rest of my code
</table>
</div>
</x-filament-panels::page>
<x-filament-panels::page>
<div class="overflow-y-auto overflow-x-auto">
<table class="w-full min-w-full dark:bg-gray-800 text-white dark:border-gray-700 rounded-xl">

@livewire('landslag.weekplan.table-header')

//Rest of my code
</table>
</div>
</x-filament-panels::page>
i also tried with this:
<livewire:landslag.weekplan.table-header />
<livewire:landslag.weekplan.table-header />
Does anyone have any clue where i can start debugging this? i've been trying for a long time now.
11 replies
FFilament
Created by torriv on 10/1/2023 in #❓┊help
Get record in custom page
I've made a custom view page where i want to display a table. In v2 i had this code:

protected function getViewData(): array
{
$data = $this->record->WorkoutExercises()->get();

return compact('data');
}

public function mount($record): void
{
$this->record = TrainingProgram::find($record);
}

protected function getViewData(): array
{
$data = $this->record->WorkoutExercises()->get();

return compact('data');
}

public function mount($record): void
{
$this->record = TrainingProgram::find($record);
}
and it still work, but i can see it's deprecated. How would we do it in v3?
4 replies
FFilament
Created by torriv on 9/30/2023 in #❓┊help
Undefined array key "recordId"
I read this thread: https://discord.com/channels/883083792112300104/1108254033795362896 but couldn't find a solution for my problem, even if it's the same error. The error is appearing when i try to save. my headerActions code is:
->headerActions([
Tables\Actions\AttachAction::make()
->label('Legg til øvelse i program')
->recordSelect(fn () => Select::make('exercise_name')
->searchable()
->preload()
->createOptionForm([
Forms\Components\TextInput::make('exercise_name'),
])
->createOptionUsing(function ($data){
$exercise = WorkoutExercise::create($data);
return $exercise->getKey();
})
->options(WorkoutExercise::pluck('exercise_name', 'id'))
)
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('repetitions')->required(),
Forms\Components\TextInput::make('sets')->required(),
Forms\Components\TimePicker::make('rest')
->native(false)
->secondsStep(10)
->displayFormat('i:s')
->format('H:i:s')
->required(),
])
])
->headerActions([
Tables\Actions\AttachAction::make()
->label('Legg til øvelse i program')
->recordSelect(fn () => Select::make('exercise_name')
->searchable()
->preload()
->createOptionForm([
Forms\Components\TextInput::make('exercise_name'),
])
->createOptionUsing(function ($data){
$exercise = WorkoutExercise::create($data);
return $exercise->getKey();
})
->options(WorkoutExercise::pluck('exercise_name', 'id'))
)
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('repetitions')->required(),
Forms\Components\TextInput::make('sets')->required(),
Forms\Components\TimePicker::make('rest')
->native(false)
->secondsStep(10)
->displayFormat('i:s')
->format('H:i:s')
->required(),
])
])
where have i messed up?
4 replies
FFilament
Created by torriv on 9/30/2023 in #❓┊help
Showing pivot data in infolist
i'm trying to show some data from a pivot table in my infolist. The infolist is like this:
public static function infolist(Infolist $infolist) : Infolist{

return $infolist
->schema([
TextEntry::make('program_name'),
RepeatableEntry::make('WorkoutExercises')
->schema([
TextEntry::make('exercise_name')->label('Øvelse'),
TextEntry::make('repetitions')->label('Reps'),
TextEntry::make('sets')->label('Set'),
TextEntry::make('rest')->label('Pause'),
])
->columns(4)
]);
}
public static function infolist(Infolist $infolist) : Infolist{

return $infolist
->schema([
TextEntry::make('program_name'),
RepeatableEntry::make('WorkoutExercises')
->schema([
TextEntry::make('exercise_name')->label('Øvelse'),
TextEntry::make('repetitions')->label('Reps'),
TextEntry::make('sets')->label('Set'),
TextEntry::make('rest')->label('Pause'),
])
->columns(4)
]);
}
The 'exercise_name' is showing, but that is from the parent table. but the rest is in the pivot table. i've tried to add the name of the pivot table, but that didn't work either. (like 'nameOfPivotTable.repetitions')
7 replies
FFilament
Created by torriv on 9/21/2023 in #❓┊help
Full screen widget
Is it possible to toggle a widget (chart widget to be specific) to show in full screen? I haven't found anything about it. I was first thinking of adding an action in the header of the widget, but that doesn't seem to be possible without making a custom widget. am i right?
11 replies
FFilament
Created by torriv on 9/17/2023 in #❓┊help
Title in repeater
Just wondering if there is a way to display a title in repeater when it is collapsed?
4 replies
FFilament
Created by torriv on 8/28/2023 in #❓┊help
getTableRecordKey(): Return value must be of type string, null
I suddenly get this error: Filament\Resources\Pages\ListRecords::getTableRecordKey(): Return value must be of type string, null returned In V2 I used to solve it by having this:
public function getTableRecordKey(Model $record): string
{
return uniqid();
}
public function getTableRecordKey(Model $record): string
{
return uniqid();
}
This doesn't seem to work anymore. this error came today after updating to the latest version. the table query:
return $table
->query(
Timesheet::query()
->select(DB::raw('DATE(DATE_FORMAT(fra_dato, \'%Y-%m-01\')) AS month, SUM(totalt) AS Totalt'))
->groupBy(DB::raw("DATE(DATE_FORMAT(fra_dato, '%Y-%m-01'))"))
->whereBetween(
'fra_dato',
[
Carbon::parse('first day of January')->format('Y-m-d H:i:s'),
Carbon::now()->endOfYear(),
]
)
->where('unavailable', 0)
)
return $table
->query(
Timesheet::query()
->select(DB::raw('DATE(DATE_FORMAT(fra_dato, \'%Y-%m-01\')) AS month, SUM(totalt) AS Totalt'))
->groupBy(DB::raw("DATE(DATE_FORMAT(fra_dato, '%Y-%m-01'))"))
->whereBetween(
'fra_dato',
[
Carbon::parse('first day of January')->format('Y-m-d H:i:s'),
Carbon::now()->endOfYear(),
]
)
->where('unavailable', 0)
)
17 replies
FFilament
Created by torriv on 8/20/2023 in #❓┊help
Sushi and Summarize()
When i try to use summarize() on a widget table, where the data comes from sushi, i get this error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '":memory:"."ynabs" where (strftime('%Y-%m-%d', "month") <= cast(? as text) and "' at line 1
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '":memory:"."ynabs" where (strftime('%Y-%m-%d', "month") <= cast(? as text) and "' at line 1
And this is the entire query:
select avg(ynabs.income) as "FvnTYOZTDbRgyL9O" from (select * from ":memory:"."ynabs" where (strftime('%Y-%m-%d', "month") <= cast(2023-08-20 as text) and "month" >= 2022-08-20 21:24:22)) as `ynabs`
select avg(ynabs.income) as "FvnTYOZTDbRgyL9O" from (select * from ":memory:"."ynabs" where (strftime('%Y-%m-%d', "month") <= cast(2023-08-20 as text) and "month" >= 2022-08-20 21:24:22)) as `ynabs`
Anyone know how to fix this?
3 replies
FFilament
Created by torriv on 8/20/2023 in #❓┊help
Forms Reactivity, hidden conditions
I have tried for a couple of days now to make a form to register some times. The
DateTimePicker
DateTimePicker
and
DatePicker
DatePicker
are hidden or shown if the user has checked the "all day" checkbox or not. The problem is that i then have to have one field with the
DateTimePicker
DateTimePicker
and one field with the
DatePicker
DatePicker
with the same field name. I didn't manage to make that work, so what i did is making those fields with different names, and add some hidden fields with the actual field names that are used in the DB and pug $set in those fake name fields in the afterStateUpdated. I managed to make it work on the create process. The problem now is on the edit page. since my fields have fake names in the schema, it won't pick the data from the DB. Do anyone have a suggestion how to solve this? Here is the stripped version of the code: https://gist.github.com/torriv83/e9bfd0bd4a219e0e1f2f5cf656f78d5a
29 replies
FFilament
Created by torriv on 8/15/2023 in #❓┊help
Route not defined , custom page
Trying to access a custom page through userMenuItems, but i get the error
Route [filament.admin.pages.settings] not defined.
Route [filament.admin.pages.settings] not defined.
Here is my AdminPanelProvider.php code:
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->profile()
->passwordReset()
->colors([
'primary' => Color::Slate,
])
->navigationItems([
..........................................
])
->navigationGroups([
.........................................
])
->userMenuItems([
MenuItem::make()
->label('Settings')
->url(route('filament.admin.pages.settings'))
->icon('heroicon-o-cog-6-tooth'),
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
//Pages\Dashboard::class,
])
->widgets([
...........................
])
->plugin(FilamentSpatieRolesPermissionsPlugin::make())
->middleware([
...............
])
->authMiddleware([
Authenticate::class,
])
->maxContentWidth('full')
->topNavigation();
}
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->profile()
->passwordReset()
->colors([
'primary' => Color::Slate,
])
->navigationItems([
..........................................
])
->navigationGroups([
.........................................
])
->userMenuItems([
MenuItem::make()
->label('Settings')
->url(route('filament.admin.pages.settings'))
->icon('heroicon-o-cog-6-tooth'),
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
//Pages\Dashboard::class,
])
->widgets([
...........................
])
->plugin(FilamentSpatieRolesPermissionsPlugin::make())
->middleware([
...............
])
->authMiddleware([
Authenticate::class,
])
->maxContentWidth('full')
->topNavigation();
}
It worked on V2. I have cleared all cache. if i remove menu item and just have a link to the page in the regular navigation, it works. Anyone have any suggestions?
5 replies
FFilament
Created by torriv on 3/7/2023 in #❓┊help
Get information from DB after selcting one option
I'm trying to make myself a place to record all my tests results (from a sport). Let's say i've just finished a strength test. Scenario: I have one table with what kind of tests i do. (for example: Bench press, pull down etc). and one table to register my results The db structure is: table name: tests - id - name - exercises (json, populate through repeater field. properties in this json is: Name and Type) table name: test-results - id - date - test I'm not sure how to set up the test-result table, but what i'm trying to do now is to choose the kind of test i'm taking, and then put in the results from my test where it gets data i need to record from the table tests. i'm not sure if i'm clear enough, just ask and i'll try to answer.
3 replies