anjama
anjama
FFilament
Created by anjama on 4/20/2024 in #❓┊help
Create child entries in RelationManager on view page of parent resource
Oh wow, I don't how many times I've been in the RelationManager docs and just completely missed that. Thank you
5 replies
FFilament
Created by anjama on 4/18/2024 in #❓┊help
Handling null id in column url to related resource
Thanks. Had to mark the return type as nullable, but otherwise it works and in a way simplifies what I was doing before
->url(fn (?int $state): ?string => $state ? BirdResource::getUrl('view', ['record' => $state]) : null),
->url(fn (?int $state): ?string => $state ? BirdResource::getUrl('view', ['record' => $state]) : null),
5 replies
FFilament
Created by anjama on 12/27/2023 in #❓┊help
Creating table filter in a trait
Laravel macros are new to me. While trying to find documentation on them, I eventually came across Dan Harrin's recent laracasts series, and it turns out one of his videos creates a custom filter and turns it into a reusable class like I was thinking about https://laracasts.com/series/build-advanced-components-for-filament/episodes/11. So I'm going to go with that approach, but now that I know about Laravel macros, I'll definitely be spending some time learning them. Edit: while creating the class, I realized I forgot to import my SoftDeleteScope class into the trait. I didn't realize that would fail silently.
5 replies
FFilament
Created by anjama on 8/22/2023 in #❓┊help
Laravel Excel not running in action
So it turns out you were on the right track. I tried giving a bad file name intentionally, and it didn't change the behavior (no exception), which made me realize that the app must be looking for the data in a different place than when I run it from the command line in tinker or a seeder. Sure enough, it's because my test data is in it's own project folder, and moving it to the storage folder fixed it.
22 replies
FFilament
Created by anjama on 8/22/2023 in #❓┊help
Laravel Excel not running in action
I just cleared the database, verified the table was empty, ran it in tinker, and now the data is in there. So it is saving them.
22 replies
FFilament
Created by anjama on 8/22/2023 in #❓┊help
Laravel Excel not running in action
I added a dd() inside the model() method of SitesImport. It didn't trigger, so it seems like it's not getting called for some reason.
22 replies
FFilament
Created by anjama on 8/22/2023 in #❓┊help
Laravel Excel not running in action
If those are needed, then why does it work without those in a seeder and in tinker?
22 replies
FFilament
Created by anjama on 8/22/2023 in #❓┊help
Laravel Excel not running in action
This just makes it so I don't have to use the Facade, no? Adding it doesn't change anything. Neither does changing it to remove use of the Facade
22 replies
FFilament
Created by anjama on 8/22/2023 in #❓┊help
Laravel Excel not running in action
To force an exception, I'm intentionally trying to add data that already exists. From tinker:
>Excel::import(new SitesImport, 'test_data/test_sites.csv');

Illuminate\Database\QueryException SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Belmore State Forest' for key 'sites.sites_site_unique' (Connection: mysql, SQL: insert into `sites` (`site`, `lat`, `lon`) values (Belmore State Forest, 29.8, -81.87)).
>Excel::import(new SitesImport, 'test_data/test_sites.csv');

Illuminate\Database\QueryException SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Belmore State Forest' for key 'sites.sites_site_unique' (Connection: mysql, SQL: insert into `sites` (`site`, `lat`, `lon`) values (Belmore State Forest, 29.8, -81.87)).
22 replies
FFilament
Created by anjama on 8/22/2023 in #❓┊help
Laravel Excel not running in action
To troubleshoot, the way I have it right now, I'm manually specifying a known existing test file and ignoring whatever file the user uploads. So the temporary uploaded file doesn't matter at the moment. Here's a simplified version to illustrate without the file upload part:
Action::make('import')
->action(function (array $data): void {

Excel::import(new SitesImport, 'test_data/test_sites.csv');

Notification::make()
->title('Action ran' )
->success()
->send();
})
Action::make('import')
->action(function (array $data): void {

Excel::import(new SitesImport, 'test_data/test_sites.csv');

Notification::make()
->title('Action ran' )
->success()
->send();
})
So now I have a button that should import that specific data into the database and then create a notification. The data is already in the database, so it should produce an exception. When I press the button, the notification occurs, but the exception doesn't. I can copy/paste the import line into tinker and it does produce the expected exception.
22 replies
FFilament
Created by anjama on 8/22/2023 in #❓┊help
Laravel Excel not running in action
class SitesImport implements ToModel, WithHeadingRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
return new Site([
"site" => $row['site'],
"lat" => $row['lat'],
"lon" => $row['lon'],
]);
}
}
class SitesImport implements ToModel, WithHeadingRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
return new Site([
"site" => $row['site'],
"lat" => $row['lat'],
"lon" => $row['lon'],
]);
}
}
It works fine outside of the action in Tinker and in a seeder
22 replies
FFilament
Created by anjama on 8/22/2023 in #❓┊help
Laravel Excel not running in action
The first dd()
array:2 [▼ // app/Filament/Resources/SampleResource/Pages/ListSamples.php:32
"data_file" => "khysB1jGuDywaAgy8Fx4oqu0iRZjn7-metadGVzdF9zaXRlcy5jc3Y=-.csv"
"file_name" => "test_sites.csv"
]
array:2 [▼ // app/Filament/Resources/SampleResource/Pages/ListSamples.php:32
"data_file" => "khysB1jGuDywaAgy8Fx4oqu0iRZjn7-metadGVzdF9zaXRlcy5jc3Y=-.csv"
"file_name" => "test_sites.csv"
]
I think it's fine; the notification part is being executed correctly. The second dd() isn't triggered, even when I intentionally try to force an exception. It's like the import line is just being skipped somehow
22 replies