Image upload in relations
I Have a
User
model with a PersonalInfo
relation:
in the PersonalInfo
we have an avatar_id
column that references to File
model:
now i just made a PersonalInfoRelationManager
to manage the relation from the UserResource
and used the FileUpload form input like this:
the upload process is fine but when i re-open to modal, image doesn't shown to me... 😦
How can I fix this issue?21 Replies
I just used this code in the TableSchema and its correctly show the Image
But the image is not load in the modal or forms after re-opening them ... 😦
relation managers are not built for hasone
the docs state that they are used on multiple relationships like hasmany and belongstomany
you shouldnt use a relation manager, you can just wrap any related fields inside a layout component - https://filamentphp.com/docs/2.x/forms/layout#saving-data-to-relationships
then the files will be uploaded from the user form into the personal data
a separate avatar relationship is absolutely overkill
@danharrin
it should not upload into the
PersonalInfo
relation.
it should upload into the File
relation that is related to the PersonalInfo
why not just use media library and make your life easy?
to store an ID instead of a path you need to copy what we did for media library which does something similar
which media library you mean?
Spatie?
its an old project and refactoring may take a long time.
what do u think?
you dont have to use it for the whole project
introduce it gradually
im just saying that an avatar relationship is 100% an overkill that you will regret. just store the file name, or use media library
ofc.
ill refactor it right now
Filament
Spatie Media Library by Dan Harrin - Plugins - Filament
Filament support for
spatie/laravel-medialibrary
.yeh
or just store the path which is much easier
we need to track the user uploads and report them in some cases
admin may changes some attributes of the uploaded File in some cases
and it MUST apply to the all places that we used the file
so we NEED TO store it in a separated table like
files
and use the id
via the relations...
any idea to make this flow easier?the file is only ever associated with 1 model, right?
no, it can be assigned to multiple models
for e.g.
we upload a
foo.png
so we have it with id 1
in the files
table
so whenever we want to use the foo.png
we just need to open a modal and let the user to select between the uploaded files that is also contains the foo.png
in it.Filament
Curator by Adam Weston - Plugins - Filament
A media picker field and media manager for Filament Admin.
full media library that allows you to attach already uploaded files
thanks for your time
i have one other question,
can i set a default path for the FileUpload field to previewing it?
i dont know what you mean
i just want to set a default image path for a FileUpload field
that it used to preview the image by default
you can pass
->default()
but otherwise noit doesn't work, dont know why actually