Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3k stars 880 forks source link

[Bug] Add HasOneThrough on relationship pro column #5531

Open dimer47 opened 1 month ago

dimer47 commented 1 month ago

Bug report

What I did

Add HasOneThrough in the relationship column pro field.

What I expected to happen

Show the value of my HasOneThrough relationship in the relationship column.

TODO

Show the value of my HasOneThrough relationship in the relationship column. File : vendor/backpack/pro/resources/views/columns/relationship.blade.php

Code :

{{-- relationships (switchboard; supports both single and multiple: 1-1, 1-n, n-n) --}}
@php
    $allowsMultiple = $crud->guessIfFieldHasMultipleFromRelationType($column['relation_type']);
    switch($column['relation_type']) {
        case 'HasOne':
        case 'MorphOne':
            $column['type'] =  isset($column['subfields']) ? 'repeatable' : 'text';
        break;
        case 'HasMany':
        case 'MorphMany':
        case 'BelongsToMany':
        case 'MorphToMany':
            $column['type'] = isset($column['subfields']) ? 'repeatable' : ($allowsMultiple ? 'select_multiple' : 'select');
        break;
        case 'BelongsTo':
        case 'HasOneThrough':
        case 'MorphTo':
            $column['type'] = 'select';
        break;
        default:
            $column['type'] = 'text';
    }
@endphp

@includeFirst(\Backpack\CRUD\ViewNamespaces::getViewPathsFor('columns', $column['type']))

Instead of

{{-- relationships (switchboard; supports both single and multiple: 1-1, 1-n, n-n) --}}
@php
    $allowsMultiple = $crud->guessIfFieldHasMultipleFromRelationType($column['relation_type']);
    switch($column['relation_type']) {
        case 'HasOne':
        case 'MorphOne':
            $column['type'] =  isset($column['subfields']) ? 'repeatable' : 'text';
        break;
        case 'HasMany':
        case 'MorphMany':
        case 'BelongsToMany':
        case 'MorphToMany':
            $column['type'] = isset($column['subfields']) ? 'repeatable' : ($allowsMultiple ? 'select_multiple' : 'select');
        break;
        case 'BelongsTo':
        case 'MorphTo':
            $column['type'] = 'select';
        break;
        default:
            $column['type'] = 'text';
    }
@endphp

@includeFirst(\Backpack\CRUD\ViewNamespaces::getViewPathsFor('columns', $column['type']))
pxpm commented 1 month ago

Hey @dimer47 hope you are doing well man 🙏

I haven't tested it, but if it's that simple we can surely give it a go.

Want to submit a PR for it or should I pick it from here ?

Cheers

dimer47 commented 1 month ago

Hello @pxpm,

I'm fine thank you, I hope you are too? I wanted to make a PR but it is a file present in the backpack PRO repo which is not a public repo or a repo to which I have access. This is why I created an issue instead of directly making a PR.

Am I wrong, do I have access to the backpack/pro repo? If so, could you tell me how?

Cheers

pxpm commented 1 month ago

Hello @pxpm,

I'm fine thank you, I hope you are too? I wanted to make a PR but it is a file present in the backpack PRO repo which is not a public repo or a repo to which I have access. This is why I created an issue instead of directly making a PR.

Am I wrong, do I have access to the backpack/pro repo? If so, could you tell me how?

Cheers

Hey @dimer47 sorry you are right.

I will add it myself and get back here with news. 🙏

Thanks