Gunnolfson
Gunnolfson
FFilament
Created by Gunnolfson on 5/13/2024 in #❓┊help
Table page without Eloquent Model
Hi, I read this page: https://filamentphp.com/docs/3.x/tables/adding-a-table-to-a-livewire-component#adding-the-table I try to implement a page where it lists some resources, but that are not Eloquent Models. It can be for example files for my backups in order to allow an admin to download it, records on external API etc. I know there is the Sushi package that allows to create eloquent models not related to DB but I don't like it so much. Is there a way to manually fetch rows and still use the abstraction of the table builder or do we have to manually write the blade file with <x-filament-tables::table> components?
7 replies
FFilament
Created by Gunnolfson on 7/15/2023 in #❓┊help
Change resource ID for FileUpload form field
Hi I did some few things to have a ULID encoded as binary(16) (needed as the Backoffice would be made from Laravel Filament, because that's the best option I know, but the project isn't a Laravel project, and that's why it is not a char(26) as Laravel handle by default) Thing is I thus need to change things like user provider, resolve router binding etc to use a decoder on the ulid value (the value stored in DB is a binary value, the one managed by Laravel is a string, thanks to casting). Here's what it looks like
public function retrieveById($identifier): Model|Builder|Authenticatable|null
{
$identifier = Ulid::fromString($identifier)->toBinary();
$model = $this->createModel();

return $this->newModelQuery($model)
->where($model->getAuthIdentifierName(), $identifier)
->first();
}
public function retrieveById($identifier): Model|Builder|Authenticatable|null
{
$identifier = Ulid::fromString($identifier)->toBinary();
$model = $this->createModel();

return $this->newModelQuery($model)
->where($model->getAuthIdentifierName(), $identifier)
->first();
}
However, when I come on an edit page for resource with a FileUpload field, I get a popup window with 404 😐 Is there anything I can do to debug it and fix it?
9 replies
FFilament
Created by Gunnolfson on 7/10/2023 in #❓┊help
Binary Ulids
3 replies
FFilament
Created by Gunnolfson on 6/27/2023 in #❓┊help
Relation manager with intermediate relationship
Hi Let's say I've an entity Foo that has many Bar, where Bar belongs to many Baz. Is that possible to have a relation manager for Foo listing the related Baz? 🤔 As far as I know, relation managers are based on Laravel Eloquent's relationships, and this isn't a base relationship. I cleary see how to retrieve these records using SQL joins, but not how to make it works with the awesome relation manager feature. Thanks 🙏
17 replies
FFilament
Created by Gunnolfson on 6/21/2023 in #❓┊help
Cannot delete test
Hi I wonder what's the easiest and most maintenable way of checking something cannot be deleted from a testing point of view. I mean, testing it is not possible from "bulking action", "table action", "page action" etc requires, imo, too much test code. I would rather look for something unique, that would look like this:
test('admin cannot delete', function () {
$admin = AdminUserFactory::new()->create();

$thing = ThingFactory::new()->create();

actingAs($admin, 'admin')
->delete(ThingResource::getUrl('delete', ['record' => $thing->getRouteKey()]))
->assertForbidden();
});
test('admin cannot delete', function () {
$admin = AdminUserFactory::new()->create();

$thing = ThingFactory::new()->create();

actingAs($admin, 'admin')
->delete(ThingResource::getUrl('delete', ['record' => $thing->getRouteKey()]))
->assertForbidden();
});
I've been adviced to use a Laravel policy to implement it. Fair enough but it is not what's relevant here. For some reasons we might not want to use a policy, and the test should be as abstract as possible from the implementations. What I mean is I don't want to have a test on a policy, but rather a "Filament test" that is more close to the feature spec than the code itself Thanks 🙏 if you have any information about this. Moved to a help post as it's not as simple as I though initially 😅
5 replies
FFilament
Created by Gunnolfson on 6/20/2023 in #❓┊help
Enable Minio S3 in Laravel Sail environment
Hi I'm making a CRUD resource for users, and it should be possible to add an avatar. However, I'm using a Laravel Sail environment with a minio container, acting as a s3 actor. I'm struggling to make Livewire FileUpload component working with this setup 😅 I got this article recommended https://talltips.novate.co.uk/livewire/livewire-file-uploads-using-s3 but it seems cors is enabled by default in minio according to https://min.io/docs/minio/linux/operations/checklists/thresholds.html#id3 this Any idea how to configure it? 🤔
3 replies
FFilament
Created by Gunnolfson on 6/20/2023 in #❓┊help
Unable to detect application namespace.
Hi I'm working on a new project. We set up an architecture based on the Laravel Beyond Crud ebook written by Spatie. We then splitted our code into Application and Domain folders. To do this, we edited the autoload section and the bootstrap.php file:
"autoload": {
"psr-4": {
"App\\": "src/Application/",
"Domain\\": "src/Domain/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"autoload": {
"psr-4": {
"App\\": "src/Application/",
"Domain\\": "src/Domain/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
$app = new Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
$app->useAppPath('src/Application');
$app = new Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
$app->useAppPath('src/Application');
I also changed some configuration inside filament.php to point out the new folders:
return [
'pages' => [
'namespace' => 'Domain\\Admin\\Pages',
'path' => app_path('../Domain/Admin/Pages'),
'register' => [
Pages\Dashboard::class,
],
],
'resources' => [
'namespace' => 'Domain\\Admin\\Resources',
'path' => app_path('../Domain/Admin/Resources'),
'register' => [],
],
'widgets' => [
'namespace' => 'Domain\\Admin\\Widgets',
'path' => app_path('../Domain/Admin/Widgets'),
'register' => [
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
],
],
'livewire' => [
'namespace' => 'Domain\\Admin',
'path' => app_path('../Domain/Admin'),
],
];
return [
'pages' => [
'namespace' => 'Domain\\Admin\\Pages',
'path' => app_path('../Domain/Admin/Pages'),
'register' => [
Pages\Dashboard::class,
],
],
'resources' => [
'namespace' => 'Domain\\Admin\\Resources',
'path' => app_path('../Domain/Admin/Resources'),
'register' => [],
],
'widgets' => [
'namespace' => 'Domain\\Admin\\Widgets',
'path' => app_path('../Domain/Admin/Widgets'),
'register' => [
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
],
],
'livewire' => [
'namespace' => 'Domain\\Admin',
'path' => app_path('../Domain/Admin'),
],
];
The test suite works well and the other pages are also working. Seems only Filament got the issue 🤔 Any idea how to debug this?
3 replies