Answer the question
In order to leave comments, you need to log in
How to attach an image or file to a model?
Hello.
Who implements the storage and linking of images to models? For example, user avatars, product photos. Maybe there are ready-made packages (modules) for laravel that allow you to do this, the task seems to be not trivial.
Answer the question
In order to leave comments, you need to log in
Create a Media model and add belongsTo to it from the field in User, and add reference to the database so that when cascad the field becomes null If you want the
picture
to be with several users, then belongsToMany and do the same with reference
There are a lot of packages, but personally it was interesting for me to initially think about how and what is better for myself to use in projects personally, so as a result I made a small blank with such a set of functionality and I transfer it from project to project
Might be worth a try as well?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question