ImageColumn disk usage and better in docs or lacks of it. subfolder structure
Hi Guys.
Question , i have this structure in storage folder , storage/app/public/uploads/banners , but i can't find any doc on how to setup this on filament , i mean , i make another disk pointing to this directory called banners ,
'banners' => [ 'driver' => 'local', 'root' => storage_path('app/public/uploads/banners'), 'url' => env('APP_URL').'/banners', 'visibility' => 'public', ],
also i made another storage link but nothing is working or showing in the table.
i'm using the disk() method in the table and the Image Column property but also no luck. the image is stored in the database without any url and just the filename and extension.
also Filament has some debug tools to implement to i can know what is retrieving all those methods ?
118 Replies
Filament doesn’t do anything to the storage class. It’s all laravel. Filament just leverages laravel’s storage facade.
What link is actually being rendered, if you inspect the source of the table? The ImageColumn definitely works with the disk() method, as long the filename in the field is a full path relative to the root of that storage disk.
As for debugging, this is just Laravel with Liuvewire. Use whatever tools you use as a Laravel developer. dd, ray, xdebug, debugbar, whatever.
Thanks for you quick response , im not getting anything in the src attribute , also seems like in the devtools is not getting anything , or any calls
Oh, and I presume you ran 'php artisan storage:link' after creating your disk in the filesystem config?
yes , i did that
also , i added another link to that
banners link
to app/public/uploads/banners
also i create a new disk like i wrote here: 'banners' => [ 'driver' => 'local', 'root' => storage_path('app/public/uploads/banners'), 'url' => env('APP_URL').'/banners', 'visibility' => 'public', ],
another thing is that the file name i just the name of the file , no url , nothing
What do you mean by you created another storage link? Running the artisan command should create any necessary links based on your filesystem config.
you can create multiple links in the public folder
at the end of the filesystem config you can add more links if you want
not just storage
Ah, OK, I thought you meant you created one by hand on the filesystem.
Did you add the path to your symlinks config for links? https://laravel.com/docs/10.x/filesystem#the-public-disk
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('banners') => storage_path('app/public/uploads/banners'),
],
Well, that answers my question. Lol.
jajja
i can read minds ..
jajaja
@awcodes you are the guy who made the Media Library ... My respects
i mean a curator plugin
Is your APP_URL set correctly?
If it helps, the FileUpload field stores it’s values, by default, as a directory/filename path. And that is read back out using the Storage facade to get the full url to the file.
And yes, I’m the author of the curator plugin.
yes
my url
http://localhost:8002/admin/banners
APP_URL=http://localhost:8002/
The funny thing its that im not getting any data from the Tables\Columns\ImageColumn::make('banner')->disk('banners')->label("Banner"),
in where banners is the disk
So you are saying when you inspect the broken link there is nothing in the src, it's entirely empty?
Like ...
<img src="" style="height: 2.5rem;" class="max-w-none object-cover object-center ring-white dark:ring-gray-900">
yes
that is
thats it
BTW, when pasting code, can you wrap it in triple backticks? Just makes this kinda conversation eaasier if the code is formatted.
sorry
Tables\Columns\ImageColumn::make('banner')->disk('banners')->label("Banner"),
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('banners') => storage_path('app/public/uploads/banners'),
],
'banners' => [ 'driver' => 'local', 'root' => storage_path('app/public/uploads/banners'), 'url' => env('APP_URL').'/banners', 'visibility' => 'public', ],
Pro tip, if it's PHP code, you can add the word php immediately after the opening tripple backtick.
nice , im new in this
Lemme dive into the code and see if it would laave that blank if it couldn't find the image. I don't think it would, I think it would just render the link regardless, but I'm not 100% sure. Back in a few.
This doesn’t make sense.
I was jus testing
Why is ‘links’ even there.
no no , this is the file filesystem.php in the config file
at the end
Given that code you’re breaking the table.
Sorry. Just the way you presented the code.
ahhh , ok ok
OK ... in getImageUrl()
... so assuming you actually have data in the field, my best guess is that there is something broken in your disk setup, such that $storage->exists() just isn't finding it.
Storage::disk(‘banners’)->exists($state)
The disk is not part of the state.
Yes , i have data in the field , and my directory is not broken
The state is a directory/filename inside of the disk.
im gonna dump this in some route
I don’t think you’re far off. Just think there’s a disconnect of what is persisted in the db and how it’s parsed.
That code I pasted takes the disk into account ... getDisk() gets the stroage driver for the disk() you configured. And $state needs to be a filepath relative to the root of that. If those two things are copacetic, it'll build a URL. Otherwise it'll be null. And from a scan of the code, that's literally the only way you could get a blank link, when you have data in the field.
im getting something
but with only disk
not exist $state , because is part of livewire no ?
No, $state is jjust the value of that row's 'banner' field, not specific to Livewire.
I have to jump into a meeting with a client. I'll check back when I'm done.
No problem , is not urgent this
its was very strange for me that didnt work
The state might be media/my-file.png, but each disk could have its own ‘media’ directory. So you have to specify the disk to tell it to look in for the ‘media’ directory. If that makes sense.
in my db , there is only the filename
The actual state that is stored in the db is a path that is relative to disk.
there is a way that i can passa function there to retrieve the data ?
i mean , what is building this ?
after label i mean
The laravel Storage facade.
Filament doesn’t do anything special. It’s just the laravel storage driver underneath the hood.
yes , i mean , can i do something tlike
All filament does it save the path to the db.
Then when reading it out it uses the storage facade with the disk specified to create the url.
im using an already exisiting db
im just migrating a site to another admin with filament
so , this dd(Storage::disk('banners')->exists('1491082289.jpg'));
Hmm. Not sure. But filament doesn’t impart anything itself on the storage or the disk.
returns true
Makes sense
Where are you seeing the problem, in a form?
the table
i tried all day scratching my head and testing whats the problem ... looking in forums and stuff , this is my last resort
If you dd($state) in the column what do you get?
where i can do that , that $state variable is a global one ?
You can use afterStateHydrated() to do that if you need to
then i pass a function ?
Actually, do it in formatStateUsing(function($record) { dd($record) })
yes
Something like that. Sorry I’m on my phone. Writing code isn’t easy. Lol.
sorry , was an old message
$state can probably be inject there too instead of $record.
Just trying to make sure the right state is being returned since it’s an existing db.
Method Filament\Tables\Columns\ImageColumn::formatStateUsing does not exist.
Try this. Change it to a text column for the time being just to see what the actual state is. https://filamentphp.com/docs/3.x/tables/columns/text#custom-formatting
seems like is not working with image column but works with text
and retrieves the value
Sorry for all the back and forth. Just trying to pin it down.
What is the actual value?
With the example you gave above for exists.
the image name
if i switch the name fo the column from image to text , i can see the name of the file.
And what is the actual value of the state?
i can use it in the Image column
i cant use this in the image column
Ok. So something is off with your disk
im runing this inside a docker container
At least know that is where the problem is now.
so, the url to the image using the link, works
Could even be the use of localhost in the App_url in your env. Disks can have problems without actual domain names.
I’ve never seen this in valet with an actual domain.test url.
also this container , do not use Traefik ,
all my other ones uses that
Even with sail and a docker container there can be internal issues with local host
Yea. Not sure something seems to me, at least, to be off with resolution of the disk.
And that is at the laravel level and not the filament level.
i migrate this from laravel 8 to 10
Since filament defaults to laravels storage facade.
and also migrate filament form 2 to 3
and not issues
Even with curator, where I’m defaulting to filament which defaults to laravel, I haven’t encountered any issues with the image column.
did you save the entire url in the dv ?
db ?
Nope. Just the path, the same as filament does
maybe that is the problem ??
its trying to find the path from the db ?
The path is the path. The image column uses the Storage facade to create the url for that path. The disk is not part of the path. It is on top of the file path.
ok
The file path is relative to the disk.
The disk is not part of the path. The disk is the “root” of the path
i just put the defaultIImageUrl , pointing to an image inside of the banners directory and seems like ImageColumn found the image and this one is not displayed
But it sounds like your disk is having problems resolving.
check this
php
TextColumn::make('banner')->label('Banner')->formatStateUsing(fn (string $state): string => url($state))
,
this returned this
sorry , my mistake
im using the text columni was getting this but i can specify the disk
i cant , fkkk my english
That’s ok. What does Storage::disk(‘banners’)->url($state) return.?
This is definitely not right.
At the least it should have your disk name on it. That how the symlinks work.
nothing , empty
wait
i forget
the return
When you symlink storage for instance. The url would be localhost:8002/storage/filename.jpg.
but , i create anotherone
called , banners
That looks right. Do you have any console errors in the browser.?
i have one , notificationBar.js
Only thing that stands out there to me is the http vs https
im running in http
I’m running out of ideas. Sorry. Still seems like a disk resolution issue to me though.
This is my disk
strange , i dont know
If you visit one of those URLs does it show the image?
yes
Yes
Well, that doesn’t make any sense. Lol.
ok, letme check something
maybe tomorrow
here is late
thanks for the help
ImageColumn::make()->disk(‘banners’) should be working.
yes , maybe is something that i have misconfigured
Let me know. Get some sleep. Sorry I couldn’t give a direct answer for you.
Solution
No problem !!! , maybe is something from this side
Thank you for you patience in working through it. I’m happy to help more if I can.
You guys are awesome keeping this alive and making some new stuff !!!
Talk soon.
Just got out of my meeting. Was supposed to be 30 minutes, but lasted over 4 hours.
You said you are running sail. Did you run artisan storage:link inside or outside the container?
Iirc, with sail you have to create the link inside the container.
If you created it outside, you'll probably need to delete that link and recreate it inside.
And I don't know if this has been fixed, but I seem to recall I ran in to an issue where even doing "sail artisan storage:link" didn't work, I actually had to open a terminal session to the container and do it inside.
@Hugh Messenger @awcodes i fixed , my bad , someone send me a bad backup with missing image files and bad db, very dumb of me not checking this up, thanks for both of you and sorry that i waste your time.