orchidsoftware / platform

Orchid is a @laravel package that allows for rapid application development of back-office applications, admin/user panels, and dashboards.
https://orchid.software
MIT License
4.26k stars 631 forks source link

save attachments with group #2670

Closed damirqa closed 10 months ago

damirqa commented 11 months ago

При загрузке файла при помощи Upload, не сохраняется group.

When uploading a file using Upload, the group is not being saved.

  1. In the save method of the Screen class, save the file as follows:

        if ($request->route('id')) {
            $informationPatients = InformationPatients::query()->where('id', $request->route('id'))->firstOrFail();
        }
    
        $informationPatients->fill($request->get('informationPatients'))->save();
        $informationPatients->load('attachment');
    
        $informationPatients->attachment('images')->syncWithoutDetaching($request->get('images'));
        $informationPatients->attachment('files')->syncWithoutDetaching($request->get('files'));
  2. Then, in the query method of the Screen class, I try to retrieve files by group name, but I receive an empty collection: $informationPatients->attachment('images')->get()

I expected to get a collection by group name. The group field in the attachments table is empty. I also have some additional questions. How can I pass attachments in Upload? $request->get('attachment', []).

Desktop (please complete the following information):

Server (please complete the following information):

tabuna commented 10 months ago

The group installation works differently. You specify to which group the field belongs, for example:

Upload::make('attachment')->groups('photos')
// ... Other fields
Upload::make('attachment')->groups('video')

Upon file upload, it is assigned a group. The values are also filtered based on this group for display. There is no need to save each group separately; it is sufficient to use:

$model->attachment()->syncWithoutDetaching($request->get('attachment'), []);