ejoi8
ejoi8
FFilament
Created by Trasek on 8/24/2024 in #❓┊help
Toggle button without database column?
Yes you can. You can try this
<?php

/**
* Toggle button to set show/hide respective field
*/
Toggle::make('show')->label(__('Show all details'))->inline()->live()
->afterStateUpdated(function (Set $set, $state) {
$set('service.show', !$state ? false : true);
}),



Tabs::make('Label')
->tabs([
Tabs\Tab::make('Service')
->icon('heroicon-m-user-circle')
->extraAttributes(['class' => 'inline-view'])
->schema([
Grid::make()
->relationship('service')
->schema([
DatePicker::make('info')
->label('Service Info')
->visible(fn(Get $get) => $get('show')) // field being show/hide base on the toggle button
])
->columns(1)
])
])
<?php

/**
* Toggle button to set show/hide respective field
*/
Toggle::make('show')->label(__('Show all details'))->inline()->live()
->afterStateUpdated(function (Set $set, $state) {
$set('service.show', !$state ? false : true);
}),



Tabs::make('Label')
->tabs([
Tabs\Tab::make('Service')
->icon('heroicon-m-user-circle')
->extraAttributes(['class' => 'inline-view'])
->schema([
Grid::make()
->relationship('service')
->schema([
DatePicker::make('info')
->label('Service Info')
->visible(fn(Get $get) => $get('show')) // field being show/hide base on the toggle button
])
->columns(1)
])
])
5 replies
FFilament
Created by ejoi8 on 2/8/2024 in #❓┊help
Export action to display data from relationships
yes, you are correct.. previously mine was v3.2.0. After I updated to v3.2.28, everything work as expected. Thank for point it out
5 replies
FFilament
Created by ejoi8 on 11/24/2023 in #❓┊help
How to "$set" Repeater itemLabel()
The idea is I want add numbering to each repeater. The list could be large so the numbering will help user to identify how many list are there I believe there could be better workaround on this and please share here if you do so.
14 replies
FFilament
Created by ejoi8 on 11/24/2023 in #❓┊help
How to "$set" Repeater itemLabel()
No description
14 replies
FFilament
Created by ejoi8 on 11/24/2023 in #❓┊help
How to "$set" Repeater itemLabel()
Select::make('quantity')
->options([
'1' => 1,
'2' => 2,
'3' => 3,
'4' => 4,
'5' => 5,
])
->afterStateUpdated(function (Get $get, Set $set) {

$name = array_map(function ($index) {
return [
'id' => $index,
'name' => '',
];
}, range(1, $get('quantity')));

$set('members', $name);

})
->live(),

Repeater::make('members')
->schema([
TextInput::make('id')->hidden(),
TextInput::make('name')->required()->label('Name'),
])
->itemLabel(fn (array $state): ?string => 'Student '.$state['id'] ?? null)
->hidden(fn (Get $get): bool => !$get('quantity'))
->addable(false)
->columns(1)
->collapsible()
->deletable(false)
->reorderable(false)
->live(),
Select::make('quantity')
->options([
'1' => 1,
'2' => 2,
'3' => 3,
'4' => 4,
'5' => 5,
])
->afterStateUpdated(function (Get $get, Set $set) {

$name = array_map(function ($index) {
return [
'id' => $index,
'name' => '',
];
}, range(1, $get('quantity')));

$set('members', $name);

})
->live(),

Repeater::make('members')
->schema([
TextInput::make('id')->hidden(),
TextInput::make('name')->required()->label('Name'),
])
->itemLabel(fn (array $state): ?string => 'Student '.$state['id'] ?? null)
->hidden(fn (Get $get): bool => !$get('quantity'))
->addable(false)
->columns(1)
->collapsible()
->deletable(false)
->reorderable(false)
->live(),
14 replies
FFilament
Created by ejoi8 on 11/24/2023 in #❓┊help
How to "$set" Repeater itemLabel()
Select::make('quantity')
->options([
'1' => 1,
'2' => 2,
'3' => 3,
'4' => 4,
'5' => 5,
])
->afterStateUpdated(function (Get $get, Set $set) {

$name = array_fill(0, $get('quantity'), [
'name' => '',
]);

$set('members', $name);
})
->live(),

Repeater::make('members')
->schema([
TextInput::make('name')->required()->label('Name'),
])
->itemLabel(function (Get $get) {
foreach ($get('members') as $key => $value) {
Log::info($get('members'));
return $key;
}
})
->hidden(fn (Get $get): bool => !$get('quantity'))
->addable(false)
->columns(1)
->collapsible()
->deletable(false)
->reorderable(false)
->live(),
Select::make('quantity')
->options([
'1' => 1,
'2' => 2,
'3' => 3,
'4' => 4,
'5' => 5,
])
->afterStateUpdated(function (Get $get, Set $set) {

$name = array_fill(0, $get('quantity'), [
'name' => '',
]);

$set('members', $name);
})
->live(),

Repeater::make('members')
->schema([
TextInput::make('name')->required()->label('Name'),
])
->itemLabel(function (Get $get) {
foreach ($get('members') as $key => $value) {
Log::info($get('members'));
return $key;
}
})
->hidden(fn (Get $get): bool => !$get('quantity'))
->addable(false)
->columns(1)
->collapsible()
->deletable(false)
->reorderable(false)
->live(),
I did this but the foreach inside itemLabel will repeat entire array. Let say I select the quantity 2, then the loop log (Log::info($get('members'))) will look something like this
[2023-11-25 02:08:49] local.INFO: array (
0 =>
array (
'name' => '',
),
1 =>
array (
'name' => '',
),
)
[2023-11-25 02:08:49] local.INFO: array (
0 =>
array (
'name' => '',
),
1 =>
array (
'name' => '',
),
)
[2023-11-25 02:08:49] local.INFO: array (
0 =>
array (
'name' => '',
),
1 =>
array (
'name' => '',
),
)
[2023-11-25 02:08:49] local.INFO: array (
0 =>
array (
'name' => '',
),
1 =>
array (
'name' => '',
),
)
Lastly, what I did is I add another id array in afterStateUpdated and add another TextInput::make('id')->hidden() in the repeater schema then add ->itemLabel(fn (array $state): ?string => 'Student '.$state['id'] ?? null). Seem like confusing but here is the full code
14 replies
FFilament
Created by ejoi8 on 11/24/2023 in #❓┊help
How to "$set" Repeater itemLabel()
alright, I will take a look into it... thanks @awcodes
14 replies
FFilament
Created by ejoi8 on 11/24/2023 in #❓┊help
How to "$set" Repeater itemLabel()
If use callback in ItemLabel, the return value still will be same to all the generated Repeater. I just want to append numbering ,maybe by using some sort of array index value but I have no idea where to start
14 replies
FFilament
Created by ejoi8 on 8/15/2023 in #❓┊help
Toggle button in InfoList
This is in panel, no custom Livewire component involved
6 replies
FFilament
Created by bellini on 8/12/2023 in #❓┊help
Basic question regarding relationships in a resource
You also can try by using Laravel Events and insert it to your related model.
protected static function booted(): void
{
static::creating(function (User $user) {
if (auth()->hasUser()) {
$user->user_id = auth()->user()->id;
}
});
}
protected static function booted(): void
{
static::creating(function (User $user) {
if (auth()->hasUser()) {
$user->user_id = auth()->user()->id;
}
});
}
6 replies
FFilament
Created by ejoi8 on 8/9/2023 in #❓┊help
Hide "anonymous" actions in create page
unfortunately the ->openUrlInNewTab() not working with ->action(). I ended download the pdf instead of viewing it in new tab. UserResource.php
Actions::make([
Action::make('pdf')
->label('Print PDF')
->form([
CheckboxList::make('category')
->options([
'profail' => 'profail',
'sale' => 'sale',
])
->bulkToggleable()
->columns(3),
])
->action(function (array $data, $state) {
$data = array_merge($data,[ 'user_id' => $state['id']]);
// Http/Controller/PdfControlelr
return (new PdfController)->generate($data);
}),
])->hiddenOn('create'),
Actions::make([
Action::make('pdf')
->label('Print PDF')
->form([
CheckboxList::make('category')
->options([
'profail' => 'profail',
'sale' => 'sale',
])
->bulkToggleable()
->columns(3),
])
->action(function (array $data, $state) {
$data = array_merge($data,[ 'user_id' => $state['id']]);
// Http/Controller/PdfControlelr
return (new PdfController)->generate($data);
}),
])->hiddenOn('create'),
PdfController.php
public function generate($data)
{
$user = User::findOrFail($data['user_id']);
$pdf = PDF::loadView('pdf.layout', compact('user','data'));
return $pdf->stream($user->id.'.pdf');
}
public function generate($data)
{
$user = User::findOrFail($data['user_id']);
$pdf = PDF::loadView('pdf.layout', compact('user','data'));
return $pdf->stream($user->id.'.pdf');
}
8 replies
FFilament
Created by ejoi8 on 8/9/2023 in #❓┊help
Hide "anonymous" actions in create page
Next how can I open new tab when the action button is clicked?
8 replies
FFilament
Created by ejoi8 on 8/9/2023 in #❓┊help
Hide "anonymous" actions in create page
ahaa.. My bad.. previously I add the hiddenOn inside the Action::make... Thank you
8 replies
FFilament
Created by Adam on 8/7/2023 in #❓┊help
Table Relationship 'name' not 'id'
If possible, try to rename the foreignId to resort_id and see how it goes. So the table column will be resort_id
13 replies
FFilament
Created by Adam on 8/7/2023 in #❓┊help
Table Relationship 'name' not 'id'
try
TextColumn::make('resort.name')
TextColumn::make('resort.name')
resort is the relation & the name is the column name
13 replies