MZX
MZX
FFilament
Created by MZX on 11/18/2024 in #❓┊help
Anyone implemented SAML in a Filament app?
Would appreciate some help.
9 replies
FFilament
Created by MZX on 11/11/2024 in #❓┊help
Export fails, even though I am exporting the exact same columns from the tables.
The table code
->columns([
TextColumn::make('scans.0.scan_time')->label('Entry Time'),
TextColumn::make('last_scan_time')->label('Exit Time'),
TextColumn::make('ronde.site.name')->label('Site'),
TextColumn::make('user.employee.first_name')->label('Employee Name'),
TextColumn::make('user.employee.supervisor.first_name')->label('Supervisor Name'),
TextColumn::make('ronde.typeDeRonde.label')->label('Ronde type'),
->columns([
TextColumn::make('scans.0.scan_time')->label('Entry Time'),
TextColumn::make('last_scan_time')->label('Exit Time'),
TextColumn::make('ronde.site.name')->label('Site'),
TextColumn::make('user.employee.first_name')->label('Employee Name'),
TextColumn::make('user.employee.supervisor.first_name')->label('Supervisor Name'),
TextColumn::make('ronde.typeDeRonde.label')->label('Ronde type'),
the exporter code
return [
ExportColumn::make('id')
->label('ID'),

ExportColumn::make('ronde.site.name')->label('Site'),
ExportColumn::make('created_at')->label('Date'),

ExportColumn::make('user.employee.first_name')->label('Employee Name'),
ExportColumn::make('scans.0.scan_time')->label('Entry Time'),
ExportColumn::make('last_scan_time')->label('Exit Time'),

ExportColumn::make('user.employee.supervisor.first_name')->label('Supervisor Name'),

ExportColumn::make('ronde.typeDeRonde.label')->label('Ronde type'),
return [
ExportColumn::make('id')
->label('ID'),

ExportColumn::make('ronde.site.name')->label('Site'),
ExportColumn::make('created_at')->label('Date'),

ExportColumn::make('user.employee.first_name')->label('Employee Name'),
ExportColumn::make('scans.0.scan_time')->label('Entry Time'),
ExportColumn::make('last_scan_time')->label('Exit Time'),

ExportColumn::make('user.employee.supervisor.first_name')->label('Supervisor Name'),

ExportColumn::make('ronde.typeDeRonde.label')->label('Ronde type'),
4 replies
FFilament
Created by MZX on 11/7/2024 in #❓┊help
Log search queries?
Is there any way i can log and save each search query on a resource list page, so we can track what users are searching the most
4 replies
FFilament
Created by MZX on 11/6/2024 in #❓┊help
Format boolean columns in exporter?
Instead of 1 and 0 I want it to bes Yes or No in the csv/xslx file.
ExportColumn::make('is_late')
->formatStateUsing(fn ($state) => $state ? 'Yes' : 'No')
->label('Late'),
ExportColumn::make('is_late')
->formatStateUsing(fn ($state) => $state ? 'Yes' : 'No')
->label('Late'),
This is what I did, but doesn't work.
5 replies
FFilament
Created by MZX on 11/2/2024 in #❓┊help
Database Notifications do not pop up?
I switched to database notifications from the regular ones, and the notifications do pile up inside the sidebar (after every polling interval) but they don't pop up. I would like them to pop up. How can I do that?
5 replies
FFilament
Created by MZX on 10/14/2024 in #❓┊help
Form not submitting user_id even though when I dd the submission the user_id is present
This is my form
return $form
->schema([
Forms\Components\Select::make('user_id')
->relationship('user', 'name')
->required(),
Forms\Components\TextInput::make('rank')
->required(),
Forms\Components\TextInput::make('no_of_research')
->required()
->numeric(),
]);
return $form
->schema([
Forms\Components\Select::make('user_id')
->relationship('user', 'name')
->required(),
Forms\Components\TextInput::make('rank')
->required(),
Forms\Components\TextInput::make('no_of_research')
->required()
->numeric(),
]);
7 replies
FFilament
Created by MZX on 10/13/2024 in #❓┊help
How to change the Resource Title?
No description
4 replies
FFilament
Created by MZX on 10/13/2024 in #❓┊help
Translate Resource and Fields
I am using the Language Switch plugin, and it translates everything automatically except the User defined stuff such as the Resources and the Fields inside. Now I know I have to make a custom file for it, but how exactly do I do it?
3 replies
FFilament
Created by MZX on 10/11/2024 in #❓┊help
Can't make it 2 columns on small screen
I have a custom widget
<x-filament-widgets::widget>
<x-filament::section>
<div class="grid grid-cols-2 gap-6 md:grid-cols-3 lg:grid-cols-5 text-center">
@foreach ($this->getNavigationItems() as $item)
<a href="{{ $item->getUrl() }}" class="p-4 border-2 border-black rounded-lg bg-red-100 shadow hover:bg-gray-100">
@if ($item->getIcon())
<x-dynamic-component :component="$item->getIcon()" class="w-6 h-6 mx-auto" />
@endif
<h3 class="mt-2 text-lg font-semibold text-red-500">{{ $item->getLabel() }}</h3>
</a>
@endforeach
</div>
</x-filament::section>
</x-filament-widgets::widget>
<x-filament-widgets::widget>
<x-filament::section>
<div class="grid grid-cols-2 gap-6 md:grid-cols-3 lg:grid-cols-5 text-center">
@foreach ($this->getNavigationItems() as $item)
<a href="{{ $item->getUrl() }}" class="p-4 border-2 border-black rounded-lg bg-red-100 shadow hover:bg-gray-100">
@if ($item->getIcon())
<x-dynamic-component :component="$item->getIcon()" class="w-6 h-6 mx-auto" />
@endif
<h3 class="mt-2 text-lg font-semibold text-red-500">{{ $item->getLabel() }}</h3>
</a>
@endforeach
</div>
</x-filament::section>
</x-filament-widgets::widget>
for some reason grid-cols-2 does not work, only 1 or 3 works. I am guessing since Filament only comes with select tailwind classes cols-2 isn't working.
6 replies
FFilament
Created by MZX on 10/1/2024 in #❓┊help
I have a custom entry (For Infolist). How to pass data to the view?
I tried this, but this didn't work. I am calling a JS function in the view which needs that data.
public function getViewData(): array
{
// Fetch the pointeau locations
return [
'pointeauLocations' => $this->getPointeauLocations(),
];
}

public function getPointeauLocations()
{
// Assuming the state refers to the `StartRonde` record
$ronde = $this->getRecord()->ronde;

// Fetch the related Pointeaux and map their locations
$locations = $ronde->pointeaux->map(function ($pointeau) {
return $pointeau->location; // Ensure this returns an array or object with lat and lng
})->toArray(); // Convert to array for easy passing to view

// Log the fetched locations
Log::info('Fetched Pointeau Locations:', $locations);

return $locations; // Return the locations
}
public function getViewData(): array
{
// Fetch the pointeau locations
return [
'pointeauLocations' => $this->getPointeauLocations(),
];
}

public function getPointeauLocations()
{
// Assuming the state refers to the `StartRonde` record
$ronde = $this->getRecord()->ronde;

// Fetch the related Pointeaux and map their locations
$locations = $ronde->pointeaux->map(function ($pointeau) {
return $pointeau->location; // Ensure this returns an array or object with lat and lng
})->toArray(); // Convert to array for easy passing to view

// Log the fetched locations
Log::info('Fetched Pointeau Locations:', $locations);

return $locations; // Return the locations
}
2 replies
FFilament
Created by MZX on 9/30/2024 in #❓┊help
Map Picker by DotSwan not fetching coordinates
This is the code, created the migrations for latitude and longitude as stated in the docs.
Map::make('location')
->label('Location')
->columnSpanFull()
->defaultLocation(latitude: 40.4168, longitude: -3.7038)
->afterStateUpdated(function (Set $set, ?array $state): void {
$set('latitude', $state['lat']);
$set('longitude', $state['lng']);
})
->afterStateHydrated(function ($state, $record, Set $set): void {
if ($record && $record->latitude && $record->longitude) {
// Set the map location to the saved latitude and longitude when editing
$set('location', ['lat' => $record->latitude, 'lng' => $record->longitude]);
}
})
->extraStyles([
'min-height: 150vh',
'border-radius: 50px'
])
->showMarker()
->markerColor("#22c55eff")
->zoom(15),
TextInput::make('latitude')
->hiddenLabel()
->hidden()
->dehydrated(), // Ensures it will be saved when the form is submitted

TextInput::make('longitude')
->hiddenLabel()
->hidden()
->dehydrated(), // Ensures it will be saved when the form is submitted
Map::make('location')
->label('Location')
->columnSpanFull()
->defaultLocation(latitude: 40.4168, longitude: -3.7038)
->afterStateUpdated(function (Set $set, ?array $state): void {
$set('latitude', $state['lat']);
$set('longitude', $state['lng']);
})
->afterStateHydrated(function ($state, $record, Set $set): void {
if ($record && $record->latitude && $record->longitude) {
// Set the map location to the saved latitude and longitude when editing
$set('location', ['lat' => $record->latitude, 'lng' => $record->longitude]);
}
})
->extraStyles([
'min-height: 150vh',
'border-radius: 50px'
])
->showMarker()
->markerColor("#22c55eff")
->zoom(15),
TextInput::make('latitude')
->hiddenLabel()
->hidden()
->dehydrated(), // Ensures it will be saved when the form is submitted

TextInput::make('longitude')
->hiddenLabel()
->hidden()
->dehydrated(), // Ensures it will be saved when the form is submitted
The latitude and longitude are empty on creating a new record.
2 replies
FFilament
Created by MZX on 9/28/2024 in #❓┊help
Use multiple guards for auth?
I have User, Employee, and Client models, and all of them will use the same Panel. I have set up the guards and everything, but the filament function
->authGuard('client')

->authGuard('client')

only allows me to put one guard, so what are my options here? (I know I can make separate panels, or just make one User table with types, but I would rather have it the way I want)
2 replies
FFilament
Created by MZX on 9/28/2024 in #❓┊help
Get the index of a repeater?
Is there any way to get the index of a repeater? Because I have to perform a comparison operation with an array of objects, and thus need the index of the repeater
6 replies
FFilament
Created by MZX on 9/27/2024 in #❓┊help
Observer causing update form to get stuck
Any idea what's causing it? This is my observer
public function updated(StartRonde $startRonde): void
{
// Check if scans are not empty
if (!empty($startRonde->scans)) {
// Count the number of references in scans
$scanCount = count($startRonde->scans);

// Fetch the associated ronde and its pointeaux
$ronde = $startRonde->ronde; // Assuming you have a relationship defined
$pointeauCount = $ronde->pointeaux()->count(); // Count the pointeaux

// Check if the counts are equal
if ($scanCount === $pointeauCount) {
// Add your logic here, for example, log a message or update a field

$startRonde->status = 'finished';
$startRonde->save(); // Save the changes to the database

} else {
// Logic for when counts do not match (optional)
Log::warning('Reference count does not match the number of Pointeaux for StartRonde ID: ' . $startRonde->id);
}
}
}
public function updated(StartRonde $startRonde): void
{
// Check if scans are not empty
if (!empty($startRonde->scans)) {
// Count the number of references in scans
$scanCount = count($startRonde->scans);

// Fetch the associated ronde and its pointeaux
$ronde = $startRonde->ronde; // Assuming you have a relationship defined
$pointeauCount = $ronde->pointeaux()->count(); // Count the pointeaux

// Check if the counts are equal
if ($scanCount === $pointeauCount) {
// Add your logic here, for example, log a message or update a field

$startRonde->status = 'finished';
$startRonde->save(); // Save the changes to the database

} else {
// Logic for when counts do not match (optional)
Log::warning('Reference count does not match the number of Pointeaux for StartRonde ID: ' . $startRonde->id);
}
}
}
9 replies
FFilament
Created by MZX on 9/26/2024 in #❓┊help
Use a JavaScript function in a form field?
I have a function for NFC, which reads a NFC tag and fetches its serial number. This serial number needs to be input in the field. How would i go about that?
3 replies
FFilament
Created by MZX on 9/24/2024 in #❓┊help
How to hide a column in a table using Filament Shield?
I have the roles set up, but i want to hide a specific column based on role
4 replies
FFilament
Created by MZX on 9/24/2024 in #❓┊help
I have a NFC reader JavaScript function, which I want to implement inside a Filament Form.
So the JS function basically reads the NFC card, and prints the data into a field. That's exactly what I want inside the form.
2 replies
FFilament
Created by MZX on 9/21/2024 in #❓┊help
Existing data not showing in the select box.
When I click on a record to edit it, the select boxes do not show the data which should be there. This is my code
return $form
->schema([
Select::make('level_id')
->label('Level')
->options(fn () => Level::all()->pluck('name', 'id')) // Fetch levels dynamically
->required()
->reactive() // React to changes in Level
->afterStateUpdated(fn (callable $set) => $set('grade_id', null)), // Reset grade when level changes

Select::make('grade_id')
->label('Grade')
->options(function (callable $get) {
$levelId = $get('level_id'); // Get the selected level_id
if ($levelId) {
return Grade::where('level_id', $levelId)->pluck('name', 'id'); // Fetch grades based on selected level
}
return [];
})
->required()
->reactive() // React to changes in Grade
->afterStateUpdated(fn (callable $set) => $set('section_id', null)), // Reset section when grade changes

Select::make('section_id')
->label('Section')
->options(function (callable $get) {
$gradeId = $get('grade_id'); // Get the selected grade_id
if ($gradeId) {
return Section::where('grade_id', $gradeId)->pluck('name', 'id'); // Fetch sections based on selected grade
}
return [];
})
->required(),
]);
return $form
->schema([
Select::make('level_id')
->label('Level')
->options(fn () => Level::all()->pluck('name', 'id')) // Fetch levels dynamically
->required()
->reactive() // React to changes in Level
->afterStateUpdated(fn (callable $set) => $set('grade_id', null)), // Reset grade when level changes

Select::make('grade_id')
->label('Grade')
->options(function (callable $get) {
$levelId = $get('level_id'); // Get the selected level_id
if ($levelId) {
return Grade::where('level_id', $levelId)->pluck('name', 'id'); // Fetch grades based on selected level
}
return [];
})
->required()
->reactive() // React to changes in Grade
->afterStateUpdated(fn (callable $set) => $set('section_id', null)), // Reset section when grade changes

Select::make('section_id')
->label('Section')
->options(function (callable $get) {
$gradeId = $get('grade_id'); // Get the selected grade_id
if ($gradeId) {
return Section::where('grade_id', $gradeId)->pluck('name', 'id'); // Fetch sections based on selected grade
}
return [];
})
->required(),
]);
28 replies
FFilament
Created by MZX on 9/14/2024 in #❓┊help
Make the table a grid of cards instead.
I have a filament resource, and instead of it being tables, i want it to be a grid of cards. How can I go about it? Does it have to be an infolist? Or can it be a table
8 replies
FFilament
Created by MZX on 9/3/2024 in #❓┊help
Fileupload not showing on Filament panel
I have a normal front-end using laravel, which has a form submission. The file uploads are stored to storage/app/directory_name/file_name But when I open the admin panel to see that record, it shows no file. The file will only show up if i save the record again after uploading the files through filament. Filament is set to use local storage.
2 replies