thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.78k stars 2.67k forks source link

Data is not inserting in related table #5512

Closed dev-paceglobal closed 2 years ago

dev-paceglobal commented 2 years ago

Laravel version

8.75.0

PHP version

8.0.12

Voyager version

1.5.2

Database

8.0.27

Description

Hey there I've some related tables and create relations according to the guide Voyger Doc
image and this is how I created the table I don't know why this isn't works I use voyeger earlier I that's work pretty fine.

Steps to reproduce

I tried to recreate the relation but not that was not works So I tried to create relations in other Breads but again I can able successfully create relations but When I Create a new record that was not hold relation table id.

Expected behavior

I want when I add the data in Medical Questionnaire Options with all data type_id attribute holds medical_questionnaire_type.id but it won't holds

Screenshots

image image image

Additional context

No response

Dri372 commented 2 years ago

Hello,

I get the same issue and do this quick workaround in vendor/tcg/voyager/src/Http/Controllers/Controller.php see modifs commented with #B5512

I don't know enough Voager to test all cases bit it works for me.

        foreach ($rows as $row) {
dump($row);    
dump($row->type);    
            // if the field for this row is absent from the request, continue
            // checkboxes will be absent when unchecked, thus they are the exception
            if (!$request->hasFile($row->field) && !$request->has($row->field) && $row->type !== 'checkbox') {
                // if the field is a belongsToMany relationship, don't remove it
                // if no content is provided, that means the relationships need to be removed
                #B512 if (isset($row->details->type) && $row->details->type !== 'belongsToMany') {
                if (isset($row->details->type) && $row->details->type !== 'belongsToMany' && $row->details->type !== 'belongsTo') { #B5512
dump("continue1");
dump($row->details->type);
dump($row->details->column);
            continue;
                }
            }

dump($row->type);    
if ($row->type == 'relationship') dump($row->details->type);
            // Value is saved from $row->details->column row
            if ($row->type == 'relationship' && $row->details->type == 'belongsTo') {
dump($row->details->column);    
                #B5512 continue;
        }

            #B5512 $content = $this->getContentBasedOnType($request, $slug, $row, $row->details);
            if ($row->type == 'relationship' && $row->details->type != 'belongsToMany') {
            $row->field = @$row->details->column;
dump("relationship row->field=".$row->field);
            }
            $content = $this->getContentBasedOnType($request, $slug, $row, $row->details);  #B5512
dev-paceglobal commented 2 years ago

@Dri372 Thanks alot friend it's work for me also 👍🏽

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.