harps
harps
FFilament
Created by harps on 7/4/2024 in #❓┊help
Query scoping
I have a model called survey that has a relationship to a model called pipe. Pipe has a json column for storing geojson as well as a WKT field for geometry calculations. I want to exclude the pipe field from being retrieved in filament to speed up page loading. I think it's automatically loaded in laravel with eager loading on the relationship. What's the best way to prevent retrieving those columns in Filament until I need them? Cheers Dan
6 replies
FFilament
Created by harps on 2/28/2024 in #❓┊help
Widget aware of relation manager
Is it possbile to get the results from the active relationmanger tab into a widget in the header of the resource view page? So if I had stat it would change when the relation tab changed?
7 replies
FFilament
Created by harps on 1/25/2024 in #❓┊help
Export action on custom page
No description
2 replies
FFilament
Created by harps on 1/10/2024 in #❓┊help
CSV validation
Is there a way to validate the contents csv before upload and provide feedback to the user on why it failed. I can create a rule with sometihng like this.
class SurveyAuditCsvRule implements Rule
{

public function passes($attribute, $value)
{
// Open the csv file.
$file = fopen($value->getRealPath(), 'r');
// Get the headers from the first line
$csvHeaders = fgetcsv($file);

// Set the header to check for
$headers = ['survey_id', 'batch_id'];

// Check if the number of columns is correct
if (count($csvHeaders) != count($headers)) {
return false;
}

// Check if the headers are correct
foreach ($csvHeaders as $header) {
if (!in_array($header, $headers)) {
return false;
}
}

// Loop through every line of the file and check if a survey with the given id exists.
while (($line = fgetcsv($file)) !== false) {
$survey = GasPipeSurvey::find($line[0]);
if (!$survey) {
return false;
}
}

// Close the file
fclose($file);

return true;
}
}
class SurveyAuditCsvRule implements Rule
{

public function passes($attribute, $value)
{
// Open the csv file.
$file = fopen($value->getRealPath(), 'r');
// Get the headers from the first line
$csvHeaders = fgetcsv($file);

// Set the header to check for
$headers = ['survey_id', 'batch_id'];

// Check if the number of columns is correct
if (count($csvHeaders) != count($headers)) {
return false;
}

// Check if the headers are correct
foreach ($csvHeaders as $header) {
if (!in_array($header, $headers)) {
return false;
}
}

// Loop through every line of the file and check if a survey with the given id exists.
while (($line = fgetcsv($file)) !== false) {
$survey = GasPipeSurvey::find($line[0]);
if (!$survey) {
return false;
}
}

// Close the file
fclose($file);

return true;
}
}
But it only returns bool not anyway of storing or displaying errors. For example looping through the sheet and checking that record exists before it can be imported. In my scenario I have a form that allows the upload of existing records that need to be replicated with slightly different values. So the user will upload a sheet with a record ids in and I want to make sure the record ID exists before I try and create the duplicates and give the user the feedback. Alternatively the feedback could be given after the csv is submitted as results of success / failures in which case how would I do that?
2 replies
FFilament
Created by harps on 1/8/2024 in #❓┊help
GetTabs actions
In a scenario where I'm using soft deletes I have an active and inactive tab but my bulk archive (delete) action shows on both active and inactive header. Is there a way to only show the archive (delete) action on the active tab?
12 replies
FFilament
Created by harps on 12/18/2023 in #❓┊help
Where to override isActiveWhen()
No description
4 replies
FFilament
Created by harps on 11/29/2023 in #❓┊help
Relation manager ignored global scope
I have a model called gaspipesurvey with a large GeoJson object column in the database. (up to 5mb). I have excluded the column using a global scope which now only returns the fields I need and this makes all the tables work fast. But I have added some relationships to the model and added then included them using getRelations() after adding each relationship each tab takes a long time to load when the GeoJson is large. Using debugbar I can see that the following query is called twice. select * from gas_pipe_surveys where gas_pipe_surveys.id = 375 limit 1 1. I wouldn't expect to see select * on this becuae of the global scope. 2. I'm not sure why it's called twice. Backtrace only shows the following
17 vendor/livewire/livewire/src/Features/SupportModels/ModelSynth.php:57
18. /vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php:218
19. /vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php:217
20. /vendor/livewire/livewire/src/Mechanisms/HandleComponents/Synthesizers/ArraySynth.php:30
21. /vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php:218
17 vendor/livewire/livewire/src/Features/SupportModels/ModelSynth.php:57
18. /vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php:218
19. /vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php:217
20. /vendor/livewire/livewire/src/Mechanisms/HandleComponents/Synthesizers/ArraySynth.php:30
21. /vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php:218
If I remove the relationships everything works ok.
4 replies
FFilament
Created by harps on 11/28/2023 in #❓┊help
Large json columns
I have a table with some large json columns and it's slowing down a resource table from loading and I don't show them on the table. How do I exclude those columns from the resource query?
7 replies
FFilament
Created by harps on 10/25/2023 in #❓┊help
Tailwind colors in color()
Can I use tailwind shade when using custom color()? I would like to use yellow-50 in my component but can't work out how to use shade. This works but only for default yellow. Color configuration
FilamentColor::register([
'red' => Color::Red,
'amber' => Color::Amber,
'green' => Color::Green,
'pressure' => Color::Yellow,
]);
FilamentColor::register([
'red' => Color::Red,
'amber' => Color::Amber,
'green' => Color::Green,
'pressure' => Color::Yellow,
]);
Component
Infolists\Components\TextEntry::make('pressure')
->label(false)
->icon('icon-gauge-outline')
->color('pressure)
->default('--'),
Infolists\Components\TextEntry::make('pressure')
->label(false)
->icon('icon-gauge-outline')
->color('pressure)
->default('--'),
How do I add the shade?
7 replies
FFilament
Created by harps on 10/25/2023 in #❓┊help
Inliine infolist entries
No description
5 replies
FFilament
Created by harps on 10/23/2023 in #❓┊help
url error on relationship
I have an infolist that renders a piece of text from a relationship and it also links to that entity in the relationship. The problem is that I'm getting an error on the url function when the relationship does not exist. What's the best way to deal with this situation?
TextEntry::make('batch.batch_name')
->label(false)
->url(fn (PipeSurvey $record): string => route('filament.admin.resources.batches.pipes.view', ['record' => PipeBatch::find($record->batch_id)])),
TextEntry::make('batch.batch_name')
->label(false)
->url(fn (PipeSurvey $record): string => route('filament.admin.resources.batches.pipes.view', ['record' => PipeBatch::find($record->batch_id)])),
9 replies
FFilament
Created by harps on 10/19/2023 in #❓┊help
hasOne model relationship select list options
I have model like client->project where each project has a foreign key client_id linked to a client. How do I create select list options in the select list that reference clients ?
3 replies
FFilament
Created by harps on 10/17/2023 in #❓┊help
Changing password error "Email already exists"
I seem to be getting this "The email address has already been taken" when changing my passwords. I have changed my user model to allow duplicate email addresses and use another uniques field 'name' for login. Not ideal but the way the client currently works we need to do it in the short term. Everything works and I can create accounts with the same email address and users login with unique name fine. The issue is that on the profile page the email field is checking for uniqueness, what os the best way to override that?
13 replies
FFilament
Created by harps on 10/13/2023 in #❓┊help
Resource view heading html
Is there any way to add html into the heading of resource view. II want to get something like <h1>Batch <span class="text-primary">AUDITS_05_10_23</span></h1> But returning html in the getHeading() function just prints the span mark up.
public function getHeading(): string
{
// Use the field batch_name from the resource as the page heading.
$heading = 'Batch <span class="text-primary">' . $this->record->batch_name . '</span>';
return new HtmlString($heading);
}
public function getHeading(): string
{
// Use the field batch_name from the resource as the page heading.
$heading = 'Batch <span class="text-primary">' . $this->record->batch_name . '</span>';
return new HtmlString($heading);
}
Cheers Dan
11 replies
FFilament
Created by harps on 10/11/2023 in #❓┊help
mutateFormDataBeforeCreate() when creating in modal
I have a function in the create class but wanted to know how I can use the same in a modal. In the docs all the life cycle hooks are in the create class too so I assume they don't work with modals either?
5 replies
FFilament
Created by harps on 10/11/2023 in #❓┊help
404 create page
I've just added a create route to a resource and I'm getting a 404, If iI remove the create key from the array then the modal works fine. I have other resources that work ok by adding and removing the create key it toggles modal on and off but not this specific resource. Have I missed something for this resource?
public static function getPages(): array
{
return [
'index' => Pages\ListProjects::route('/'),
'view' => Pages\ViewProject::route('/{record}'),
'create' => Pages\CreateProject::route('/create'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListProjects::route('/'),
'view' => Pages\ViewProject::route('/{record}'),
'create' => Pages\CreateProject::route('/create'),
];
}
Uaing xdebug and puasing exceptions I get the following errors. "File does not exist at path /app/storage/framework/cache/data/47/e0/47e0354a704ca2aab47ed06ea898849d8a435dfe." "No query results for model [App\Models\Project] create" I have other models / resources that are working, I can't work out why this one is different.
5 replies
FFilament
Created by harps on 10/10/2023 in #❓┊help
Use record ID for file folder path
How would I use the record ID in the folder path to store files? I have tried the following
Forms\Components\FileUpload::make('shape_file')
->preserveFilenames()
// directory is record id of the project
->directory(fn ($record) => 'project-shapes/' . $record->id)
->previewable(false)
->downloadable()
->disk('private')
->visibility('public'),
Forms\Components\FileUpload::make('shape_file')
->preserveFilenames()
// directory is record id of the project
->directory(fn ($record) => 'project-shapes/' . $record->id)
->previewable(false)
->downloadable()
->disk('private')
->visibility('public'),
but get an error when creating new because the record does not exist yet. It does work if I create the record first then edit as the record already exists.
10 replies
FFilament
Created by harps on 10/6/2023 in #❓┊help
Download private files
I'm trying to create a scenario where only logged in users can see uploaded files, I've seen it asked here a few times but I can't make sense of the answers. I have this public static function form(Form $form): Form { return $form ->schema([ Forms\Components\Select::make('client_id') ->relationship(name: 'client', titleAttribute: 'client_name'), Forms\Components\TextInput::make('project_name') ->required() ->maxLength(100), Forms\Components\FileUpload::make('shape_file') ->preserveFilenames() // directory is record id of the project ->directory(fn ($record) => 'project-shapes/' . $record->id) ->previewable(false) ->downloadable() ->disk('private') ]); } and this in the filesystem config 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), 'url' => env('APP_URL').'/storage', 'visibility' => 'public', 'throw' => false, ], 'private' => [ 'driver' => 'local', 'root' => storage_path('app/private'), 'url' => env('APP_URL').'/storage', 'visibility' => 'private', 'throw' => false, ], I have public sym linked. Everything works including event listeners for deleting but I can't download the file from the form. I would also like to have an icon link in the resource table to the file. Thanks Dan
4 replies
FFilament
Created by harps on 10/2/2023 in #❓┊help
modal notification title
How do I change the notification if the create resource is loaded in a modal? protected function getCreatedNotificationTitle(): ?string { return 'Client created successfully!'; } I can do the above on the edit page but that doesn't change the notification if I create a new client in a modal. Thanks
5 replies