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 ?
Solution:
No problem !!! , maybe is something from this side
Jump to solution
118 Replies
awcodes
awcodes15mo ago
Filament doesn’t do anything to the storage class. It’s all laravel. Filament just leverages laravel’s storage facade.
cheesegrits
cheesegrits15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
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
cheesegrits
cheesegrits15mo ago
Oh, and I presume you ran 'php artisan storage:link' after creating your disk in the filesystem config?
Suicidalpain
SuicidalpainOP15mo ago
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
cheesegrits
cheesegrits15mo ago
What do you mean by you created another storage link? Running the artisan command should create any necessary links based on your filesystem config.
Suicidalpain
SuicidalpainOP15mo ago
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
cheesegrits
cheesegrits15mo ago
Ah, OK, I thought you meant you created one by hand on the filesystem.
awcodes
awcodes15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
'links' => [ public_path('storage') => storage_path('app/public'), public_path('banners') => storage_path('app/public/uploads/banners'), ],
awcodes
awcodes15mo ago
Well, that answers my question. Lol.
Suicidalpain
SuicidalpainOP15mo ago
jajja i can read minds .. jajaja @awcodes you are the guy who made the Media Library ... My respects i mean a curator plugin
cheesegrits
cheesegrits15mo ago
Is your APP_URL set correctly?
awcodes
awcodes15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
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
cheesegrits
cheesegrits15mo ago
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">
Suicidalpain
SuicidalpainOP15mo ago
yes that is thats it
Suicidalpain
SuicidalpainOP15mo ago
No description
cheesegrits
cheesegrits15mo ago
BTW, when pasting code, can you wrap it in triple backticks? Just makes this kinda conversation eaasier if the code is formatted.
Suicidalpain
SuicidalpainOP15mo ago
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', ],
cheesegrits
cheesegrits15mo ago
Pro tip, if it's PHP code, you can add the word php immediately after the opening tripple backtick.
Suicidalpain
SuicidalpainOP15mo ago
nice , im new in this
cheesegrits
cheesegrits15mo ago
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.
awcodes
awcodes15mo ago
This doesn’t make sense.
Suicidalpain
SuicidalpainOP15mo ago
I was jus testing
awcodes
awcodes15mo ago
Why is ‘links’ even there.
Suicidalpain
SuicidalpainOP15mo ago
no no , this is the file filesystem.php in the config file at the end
awcodes
awcodes15mo ago
Given that code you’re breaking the table. Sorry. Just the way you presented the code.
Suicidalpain
SuicidalpainOP15mo ago
ahhh , ok ok
cheesegrits
cheesegrits15mo ago
OK ... in getImageUrl()
if (! $storage->exists($state)) {
return null;
}
if (! $storage->exists($state)) {
return null;
}
... 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.
awcodes
awcodes15mo ago
Storage::disk(‘banners’)->exists($state) The disk is not part of the state.
Suicidalpain
SuicidalpainOP15mo ago
Yes , i have data in the field , and my directory is not broken
awcodes
awcodes15mo ago
The state is a directory/filename inside of the disk.
Suicidalpain
SuicidalpainOP15mo ago
im gonna dump this in some route
awcodes
awcodes15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
No description
cheesegrits
cheesegrits15mo ago
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.
$storage = $this->getDisk();

try {
if (! $storage->exists($state)) {
return null;
}
} catch (UnableToCheckFileExistence $exception) {
return null;
}
$storage = $this->getDisk();

try {
if (! $storage->exists($state)) {
return null;
}
} catch (UnableToCheckFileExistence $exception) {
return null;
}
Suicidalpain
SuicidalpainOP15mo ago
im getting something but with only disk not exist $state , because is part of livewire no ?
cheesegrits
cheesegrits15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
No problem , is not urgent this its was very strange for me that didnt work
awcodes
awcodes15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
in my db , there is only the filename
awcodes
awcodes15mo ago
The actual state that is stored in the db is a path that is relative to disk.
Suicidalpain
SuicidalpainOP15mo ago
there is a way that i can passa function there to retrieve the data ? i mean , what is building this ? after label i mean
awcodes
awcodes15mo ago
The laravel Storage facade. Filament doesn’t do anything special. It’s just the laravel storage driver underneath the hood.
Suicidalpain
SuicidalpainOP15mo ago
yes , i mean , can i do something tlike
awcodes
awcodes15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
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'));
awcodes
awcodes15mo ago
Hmm. Not sure. But filament doesn’t impart anything itself on the storage or the disk.
Suicidalpain
SuicidalpainOP15mo ago
returns true
awcodes
awcodes15mo ago
Makes sense Where are you seeing the problem, in a form?
Suicidalpain
SuicidalpainOP15mo ago
the table i tried all day scratching my head and testing whats the problem ... looking in forums and stuff , this is my last resort
awcodes
awcodes15mo ago
If you dd($state) in the column what do you get?
Suicidalpain
SuicidalpainOP15mo ago
where i can do that , that $state variable is a global one ?
awcodes
awcodes15mo ago
You can use afterStateHydrated() to do that if you need to
Suicidalpain
SuicidalpainOP15mo ago
then i pass a function ?
awcodes
awcodes15mo ago
Actually, do it in formatStateUsing(function($record) { dd($record) })
Suicidalpain
SuicidalpainOP15mo ago
yes
awcodes
awcodes15mo ago
Something like that. Sorry I’m on my phone. Writing code isn’t easy. Lol.
Suicidalpain
SuicidalpainOP15mo ago
sorry , was an old message
awcodes
awcodes15mo ago
$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.
Suicidalpain
SuicidalpainOP15mo ago
Method Filament\Tables\Columns\ImageColumn::formatStateUsing does not exist.
awcodes
awcodes15mo ago
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
Suicidalpain
SuicidalpainOP15mo ago
seems like is not working with image column but works with text and retrieves the value
awcodes
awcodes15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
the image name if i switch the name fo the column from image to text , i can see the name of the file.
awcodes
awcodes15mo ago
And what is the actual value of the state?
Suicidalpain
SuicidalpainOP15mo ago
No description
Suicidalpain
SuicidalpainOP15mo ago
i can use it in the Image column i cant use this in the image column
awcodes
awcodes15mo ago
Ok. So something is off with your disk
Suicidalpain
SuicidalpainOP15mo ago
im runing this inside a docker container
awcodes
awcodes15mo ago
At least know that is where the problem is now.
Suicidalpain
SuicidalpainOP15mo ago
so, the url to the image using the link, works
awcodes
awcodes15mo ago
Could even be the use of localhost in the App_url in your env. Disks can have problems without actual domain names.
Suicidalpain
SuicidalpainOP15mo ago
No description
awcodes
awcodes15mo ago
I’ve never seen this in valet with an actual domain.test url.
Suicidalpain
SuicidalpainOP15mo ago
also this container , do not use Traefik , all my other ones uses that
awcodes
awcodes15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
i migrate this from laravel 8 to 10
awcodes
awcodes15mo ago
Since filament defaults to laravels storage facade.
Suicidalpain
SuicidalpainOP15mo ago
and also migrate filament form 2 to 3 and not issues
awcodes
awcodes15mo ago
Even with curator, where I’m defaulting to filament which defaults to laravel, I haven’t encountered any issues with the image column.
Suicidalpain
SuicidalpainOP15mo ago
did you save the entire url in the dv ? db ?
awcodes
awcodes15mo ago
Nope. Just the path, the same as filament does
Suicidalpain
SuicidalpainOP15mo ago
maybe that is the problem ?? its trying to find the path from the db ?
awcodes
awcodes15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
ok
awcodes
awcodes15mo ago
The file path is relative to the disk. The disk is not part of the path. The disk is the “root” of the path
Suicidalpain
SuicidalpainOP15mo ago
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
awcodes
awcodes15mo ago
But it sounds like your disk is having problems resolving.
Suicidalpain
SuicidalpainOP15mo ago
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 column
Suicidalpain
SuicidalpainOP15mo ago
No description
Suicidalpain
SuicidalpainOP15mo ago
i was getting this but i can specify the disk i cant , fkkk my english
awcodes
awcodes15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
No description
Suicidalpain
SuicidalpainOP15mo ago
nothing , empty wait i forget the return
awcodes
awcodes15mo ago
When you symlink storage for instance. The url would be localhost:8002/storage/filename.jpg.
Suicidalpain
SuicidalpainOP15mo ago
No description
Suicidalpain
SuicidalpainOP15mo ago
but , i create anotherone called , banners
awcodes
awcodes15mo ago
That looks right. Do you have any console errors in the browser.?
Suicidalpain
SuicidalpainOP15mo ago
i have one , notificationBar.js
awcodes
awcodes15mo ago
Only thing that stands out there to me is the http vs https
Suicidalpain
SuicidalpainOP15mo ago
im running in http
awcodes
awcodes15mo ago
I’m running out of ideas. Sorry. Still seems like a disk resolution issue to me though.
Suicidalpain
SuicidalpainOP15mo ago
This is my disk strange , i dont know
awcodes
awcodes15mo ago
If you visit one of those URLs does it show the image?
Suicidalpain
SuicidalpainOP15mo ago
yes Yes
awcodes
awcodes15mo ago
Well, that doesn’t make any sense. Lol.
Suicidalpain
SuicidalpainOP15mo ago
ok, letme check something maybe tomorrow here is late thanks for the help
awcodes
awcodes15mo ago
ImageColumn::make()->disk(‘banners’) should be working.
Suicidalpain
SuicidalpainOP15mo ago
yes , maybe is something that i have misconfigured
awcodes
awcodes15mo ago
Let me know. Get some sleep. Sorry I couldn’t give a direct answer for you.
Solution
Suicidalpain
Suicidalpain15mo ago
No problem !!! , maybe is something from this side
awcodes
awcodes15mo ago
Thank you for you patience in working through it. I’m happy to help more if I can.
Suicidalpain
SuicidalpainOP15mo ago
You guys are awesome keeping this alive and making some new stuff !!!
awcodes
awcodes15mo ago
Talk soon.
cheesegrits
cheesegrits15mo ago
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.
Suicidalpain
SuicidalpainOP15mo ago
@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.
Want results from more Discord servers?
Add your server