V
V
Vyacheslav Shevchenko2021-05-14 18:53:58
Laravel
Vyacheslav Shevchenko, 2021-05-14 18:53:58

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

1 answer(s)
V
Vladimir Kudrya, 2021-05-14
@WebDev2030

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 question

Ask a Question

731 491 924 answers to any question