benshawuk
benshawuk
FFilament
Created by benshawuk on 11/9/2023 in #❓┊help
What is missing if you don't use panel builder?
Just to understand this philosophically, if you were to build a custom Laravel app/site using most or all of the Filament classes/concepts - i.e. Form builder, Table builder, Notifications, Actions, Infolists, and widgets... Basically everything but the panel builder itself, what would be left/missing? My guess is that you'd need to roll your own navbar, login/registration, sidebar, CSS page layout etc. Also, you'd need to manage your own routes/auth. Would you also need to provide your own styling for everything, or does table/form builder etc. still use the Filament styling? And would I also be right in thinking that Filament plugins wouldn't work either (as they're depending on a panel to be there)? Would it still be possible to implement global search also? Any feedback as to how accurate these assumptions are would be appreciated, and also if I've missed anything off the "wouldn't be included/possible without a panel" list. I'm asking this as a client has a particular use case where they want a heavily customised/branded layout (inline with some of their other systems) but I still see lots of use for the core concepts of Filament for this project. Many thanks.
5 replies
FFilament
Created by benshawuk on 10/30/2023 in #❓┊help
Resources/js/app.js and css/app.css not working
Not sure what I'm missing here, but any CSS or JS I add to these files are not having any effect. I've tried npm run build and restarting my web server but it's as though those files are just getting completely ignored. I've also tried artisan cache:clear and artisan view:clear Any help/suggestions appreciated. Thanks.
10 replies
FFilament
Created by benshawuk on 7/15/2023 in #❓┊help
Reactive file upload firing garbled info for file names
I have a standard file upload field that has reactive() on it. I can access other form fields reactively, but when I try and access the "attachments" field on a reactive file upload (to get the name of the file that has just been uploaded), I get this:
Array ( [67c51498-b77e-4025-8604-ac2f3dce03e5] => Livewire\TemporaryUploadedFile Object ( [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 3I7PK9zxev1FgMWfi6jTWT3yW25qcV-metadGVzdHh4LnBkZg==-.pdf [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => application/octet-stream [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0 [hashName:protected] => [storage:protected] => Illuminate\Filesystem\FilesystemAdapter Object ( [driver:protected] => League\Flysystem\Filesystem Object ( [config:League\Flysystem\Filesystem:private] => League\Flysystem\Config Object ( [options:League\Flysystem\Config:private] => Array ( ) ) [pathNormalizer:League\Flysystem\Filesystem:private] => League\Flysystem\WhitespacePathNormalizer Object ( ) [adapter:League\Flysystem\Filesystem:private] => League\Flysystem\Local\LocalFilesystemAdapter Object ( [prefixer:League\Flysystem\Local\LocalFilesystemAdapter:private] => League\Flysystem\PathPrefixer Object ( [prefix:League\Flysystem\PathPrefixer:private]....
Array ( [67c51498-b77e-4025-8604-ac2f3dce03e5] => Livewire\TemporaryUploadedFile Object ( [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 3I7PK9zxev1FgMWfi6jTWT3yW25qcV-metadGVzdHh4LnBkZg==-.pdf [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => application/octet-stream [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0 [hashName:protected] => [storage:protected] => Illuminate\Filesystem\FilesystemAdapter Object ( [driver:protected] => League\Flysystem\Filesystem Object ( [config:League\Flysystem\Filesystem:private] => League\Flysystem\Config Object ( [options:League\Flysystem\Config:private] => Array ( ) ) [pathNormalizer:League\Flysystem\Filesystem:private] => League\Flysystem\WhitespacePathNormalizer Object ( ) [adapter:League\Flysystem\Filesystem:private] => League\Flysystem\Local\LocalFilesystemAdapter Object ( [prefixer:League\Flysystem\Local\LocalFilesystemAdapter:private] => League\Flysystem\PathPrefixer Object ( [prefix:League\Flysystem\PathPrefixer:private]....
etc. If I save and refresh the page, it correctly gives me:
Array ( [c7d2a2c1-2dbe-4fd3-b649-a8a5b373a507] => testxx.pdf )
Array ( [c7d2a2c1-2dbe-4fd3-b649-a8a5b373a507] => testxx.pdf )
What is going on here? It's like the reactive() is firing before the field has a chance to update itself properly? Does anyone know of a better way to achieve this? I just need to grab the file name for displaying in another field.
10 replies
FFilament
Created by benshawuk on 7/15/2023 in #❓┊help
ColumnSpan/grid issue with form groups
How do I make my first group span 2/3 of the page space, and the second one 1/3? I've tried various combinations of columns and columnSpan but both always seem to take 1/2 the page each..
return $form
->schema([

Forms\Components\Group::make()
->schema([
Forms\Components\Section::make('Upload File')
->schema([
Forms\Components\FileUpload::make('attachments')
->preserveFilenames()
->acceptedFileTypes(['application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'image/jpeg', 'image/png', 'text/plain'])
->maxSize(1024)
->enableDownload()
->imagePreviewHeight('250')
->loadingIndicatorPosition('left')
->panelAspectRatio('7:1')
])
]),

Forms\Components\Group::make()
->schema([
Forms\Components\Section::make('Visibility')
->schema([
Forms\Components\Toggle::make('is_private')
->label('🔒 Private')
->helperText('If enabled, this file will only be accessible by you.')
->default(false),
])
]),
return $form
->schema([

Forms\Components\Group::make()
->schema([
Forms\Components\Section::make('Upload File')
->schema([
Forms\Components\FileUpload::make('attachments')
->preserveFilenames()
->acceptedFileTypes(['application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'image/jpeg', 'image/png', 'text/plain'])
->maxSize(1024)
->enableDownload()
->imagePreviewHeight('250')
->loadingIndicatorPosition('left')
->panelAspectRatio('7:1')
])
]),

Forms\Components\Group::make()
->schema([
Forms\Components\Section::make('Visibility')
->schema([
Forms\Components\Toggle::make('is_private')
->label('🔒 Private')
->helperText('If enabled, this file will only be accessible by you.')
->default(false),
])
]),
3 replies
FFilament
Created by benshawuk on 7/8/2023 in #❓┊help
Fileupload (Filepond) custom preview
Can anyone nudge me in the right direction for this? (I'm not hoping for a solution, just a general "how I might go about this").. So when you upload a png or jpg for example, FilePond gives you a preview of the image. But if I upload a PDF or word document, I want to show a custom icon (I have these already) of a file with the PDF logo on, etc. instead of just a block of green or grey. I'm guessing this is custom javascript, but how do I access these properties in the context of Filament? And get Filament to understand how to render the Filepond file with the custom icon of my choosing? (I hope that makes sense). I'm open to SpatieMedia or other 3rd party solutions also, if that's more appropriate for this? Also, when I hit cancel after saving an uploaded file, I get stuck in an infinite loop of it loading the same "edit" page.. Is that a bug? Or do I need a custom "exit" button?
11 replies
FFilament
Created by benshawuk on 7/5/2023 in #❓┊help
File upload not getting "stored" with record
I have a super basic file upload:
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\FileUpload::make('File Upload')
->columnSpan('full')
->preserveFilenames()
->acceptedFileTypes(['image/png'])
->maxSize(1024)
->storeFileNamesIn('file_name')
->enableDownload(),
Forms\Components\TextArea::make('notes')
->columnSpan('full')
->rows(4)
......
]);

}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\FileUpload::make('File Upload')
->columnSpan('full')
->preserveFilenames()
->acceptedFileTypes(['image/png'])
->maxSize(1024)
->storeFileNamesIn('file_name')
->enableDownload(),
Forms\Components\TextArea::make('notes')
->columnSpan('full')
->rows(4)
......
]);

}
I can successfully upload an image, see it in the file system (storage folder), get no console or PHP errors etc. but when I save, then refresh the page, the file preview is gone, as if the file was never uploaded, or like I'm looking at a blank/new record. This is probably something really obvious, but what am I missing here? Is there some special database field (other than file_name) that I need to have configured? (Also, my APP_URL is definitely configured correctly). Or do I need the Spatie plugin to preserve image previews?
9 replies
FFilament
Created by benshawuk on 6/26/2023 in #❓┊help
Correct way to add additional middleware route groups
I have managed to get Jetstream's "EmailVerified" functionality working with Filament by wrapping the resource and pages route groups around it in vendor/filament/filament/routes/web.php :
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
Route::middleware(config('filament.middleware.auth'))->group(function (): void {
Route::name('pages.')->group(function (): void {
foreach (Filament::getPages() as $page) {
Route::group([], $page::getRoutes());
}
});

Route::name('resources.')->group(function (): void {
foreach (Filament::getResources() as $resource) {
Route::group([], $resource::getRoutes());
}
});
});
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
Route::middleware(config('filament.middleware.auth'))->group(function (): void {
Route::name('pages.')->group(function (): void {
foreach (Filament::getPages() as $page) {
Route::group([], $page::getRoutes());
}
});

Route::name('resources.')->group(function (): void {
foreach (Filament::getResources() as $resource) {
Route::group([], $resource::getRoutes());
}
});
});
Obviously this isn't ideal, nor would be publishing the routes file (if that's even possible). Is there a way I can achieve the same result by adding to the middleware section of the Filament config? Or some other place? If so, what would be the syntax for this? If I try and add the middleware route groups in my main web.php, it doesn't respect/know about the Filament ones.
4 replies
FFilament
Created by benshawuk on 6/24/2023 in #❓┊help
Is there a way to "stack" filters?
For example if I have a select filter that shows "Book 1, Book 2, Book 3" and then I have a second select filter called "chapter". Rather than showing all chapters from all books, it would then show just the chapters from the book selected in the previous filter. I hope that makes sense, essentially the contents of the second select filter would be filtered from the already filtered results..
8 replies
FFilament
Created by benshawuk on 6/21/2023 in #❓┊help
What is the correct way to automatically pass in a form value (on the backend)?
I'm using this, which doesn't feel secure:
Forms\Components\Hidden::make('company_id')
->required()
->default(auth()->user()->company_id),
Forms\Components\Hidden::make('company_id')
->required()
->default(auth()->user()->company_id),
Should I be setting something at the model level? I did search the docs, but wasn't quite sure where to look to find this.
6 replies
FFilament
Created by benshawuk on 6/18/2023 in #❓┊help
Wasted white space on filters above table
8 replies
FFilament
Created by benshawuk on 6/15/2023 in #❓┊help
Navigation group not respecting shield permissions
When I don't have a builder navigation group in the app service provider's boot method, Filament Shields permissions are respected, and navigation items hidden according to permission. But when I add my navigation groups using builder, all users can see every resource in the navigation sidebar.. Is there something I can do to get it to respect the permissions in the same way? Maybe something I need to put in ->isActiveWhen without manually hard coding each one to each specific permission that is already set in shield? Filament::navigation(function (NavigationBuilder $builder): NavigationBuilder { return $builder ->items([ NavigationItem::make('Dashboard') ->icon('heroicon-o-home') ->activeIcon('heroicon-s-home') ->isActiveWhen(fn (): bool => request()->routeIs('filament.pages.dashboard')) ->url(route('filament.pages.dashboard')), ]) ->groups([ NavigationGroup::make('Settings') ->items([ ...Profile::getNavigationItems(), ]), NavigationGroup::make('Site Admin') ->items([ ...UserResource::getNavigationItems(), ]), NavigationGroup::make('Super Admin') ->items([ ...CompanyResource::getNavigationItems(), ...AllUserResource::getNavigationItems(), ...RoleResource::getNavigationItems(), ]), ]); });
16 replies
FFilament
Created by benshawuk on 6/12/2023 in #❓┊help
Creating a new resource reusing an existing model
I'm trying to set up an "all users" resource that uses the same 'users' DB table as my "users" resource. However, in order for Filament to recognise it as a different resource (so that I can customise the fields and get a new link in the sidebar etc.) I have had to create a new resource and a new model (allUsers). Or am I going about this all wrong? What is the most sensible way of essentially replicating a resource (with a different name and URL) and then re-customising it with different options, whilst sharing the same database table?
95 replies
FFilament
Created by benshawuk on 6/10/2023 in #❓┊help
Lifecycle Hooks on simple resources
Where do I apply these? In the documentation it says: You can use the before() and after() methods to execute code before and after a record is deleted: DeleteAction::make() ->before(function () { // ... }) ->after(function () { // ... }) But where does this code go? In the page resource? For the edit life cycle hook it says: "To set up a hook, create a protected method on the Edit page class with the name of the hook:" I'm using a simple resource (modal editing only, so doesn't have an edit page?). Is this not possible, or is there another place to utilise the life cycle hooks for this case?
27 replies
FFilament
Created by benshawuk on 6/9/2023 in #❓┊help
RichEditor new lines are double spaced
Is there a way of making it so that when you hit return, it only goes to the next line instead of two lines down? It's as though it's permanently lodged in double spaced mode. Normally with this, shift and return takes you to the next line, but not in this case.
17 replies
FFilament
Created by benshawuk on 6/9/2023 in #❓┊help
Modal window jumps to left a tiny bit when closing
I know it's a very small thing, but does anyone know a way of stopping this happening, or is it a bug? It's easy to reproduce - open any editor modal (even on the Filamant Demo site) and cancel out, and it jumps to the left a tiny bit just as it starts the closing animation. (MacOS on Chrome, Firefox & Safari)
9 replies
FFilament
Created by benshawuk on 6/9/2023 in #❓┊help
Toggle switches not displaying correctly
12 replies
FFilament
Created by benshawuk on 6/8/2023 in #❓┊help
How do I eager load this?
Select::make('roles') ->required() ->multiple() ->relationship('roles', 'name') I want the role names to be populated without having to start typing to find them.. I know this seems obvious and I recall reading it in the documentation previously, but I can't seem to find it now.
5 replies
FFilament
Created by benshawuk on 6/4/2023 in #❓┊help
Populating select drop down with correct Spatie role value
I can display a user's associated Spatie role in a table like this: ->columns([ Tables\Columns\BadgeColumn::make('roles.name'), ]) When I want to edit the user form with a select menu, I can also display the names of the roles like this: Select::make('role') ->required() ->relationship('role', 'name'), The problem is, it doesn't seem to pick up the current value of the role in the select dropdown menu.. How do I get it to default to the current value? If it was my own "roles" model, I'd add a relationship function in there, but in this case it's getting it from the Spatie role model. I tried to add a custom model to add the relationship, but that didn't work either: use Spatie\Permission\Models\Role; class CustomRole extends Role { // Additional customizations here public function customrole() { return $this->hasMany(Role::class); } }
14 replies
FFilament
Created by benshawuk on 6/4/2023 in #❓┊help
Restrict access to resource with Spatie
I have Spatie installed and have created an "admin" role. I can then add my seeded users to that role, where required. How do I use ->hasRole('Admin'); to allow access to a resource (and deny if the user doesn't have that role)? So that it isn't accessible and doesn't show up in the navigation side bar unless the user has that role? I don't need to do anything more fancy than that, and don't need to block the entire admin panel using public function canAccessFilament():, but just particular resources.
6 replies
FFilament
Created by benshawuk on 6/3/2023 in #❓┊help
Can I use relationships in a form like this?
I have a table that successfully uses a relationship from another table: Tables\Columns\TextColumn::make('company.company_name'), This displays the company name due to the relation setup in the model. But when I try and replicate this for the form, it doesn't work: Forms\Components\Select::make('company.company_name') ->required() How do I get the select drop down to show the company names? (and write the ID back to the database when editing the records)?
4 replies