Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag fields show parent resource as taggable options when created via a relationship #6664

Closed
cedricblom opened this issue Jan 13, 2025 · 2 comments
Labels

Comments

@cedricblom
Copy link

  • Laravel Version: 11.37.0
  • Nova Version: 4.35.5
  • PHP Version: 8.3.15

Description:

Tag fields will populate with the incorrect resource when the resource holding the tag field was created via a relationship. This is presumable caused by line 30 of the Laravel\Nova\Http\Requests\ResourceSearchRequest class. Instead of $this->newQuery() one should presumable call $model->newQuery(), since $this->newQuery() is checking the "viaRelationship".
Admittedly, I do not oversee the consquences of such a change.

I think this is what the ResourceSearchRequest class should look like (it works for me):

<?php

namespace Laravel\Nova\Http\Requests;

use Laravel\Nova\Contracts\QueryBuilder;

class ResourceSearchRequest extends NovaRequest
{
    use QueriesResources;

    /**
     * Get the paginator instance for the index request.
     *
     * @return \Illuminate\Database\Eloquent\Collection
     */
    public function searchIndex()
    {
        $resource = $this->resource();
        $model = $this->model();

        $limit = $resource::usesScout()
                    ? $resource::$scoutSearchResults
                    : $resource::$relatableSearchResults;

        $query = app()->make(QueryBuilder::class, [$resource]);

        $this->first === 'true'
                        ? $query->whereKey($model->newQueryWithoutScopes(), $this->current)
                        : $query->search(
                            $this, $model->newQuery(), $this->search,
                            $this->filters()->all(), $this->orderings(), $this->trashed()
                        );

        return $query->take($limit)->get();
    }
}

Detailed steps to reproduce the issue on a fresh Nova installation:

  1. Create a parent resource that has some kind of child relation (e.g. a HasMany relation).
  2. Create the child resource that has a tag field. The tag field should reference some kind of tag resource that I will refer to as "SomeTag".
  3. Make sure there are a few tags in the "SomeTag" table.
  4. Now when you search the tag field for available SomeTag's, it will show parent resources instead.
@crynobone
Copy link
Member

Please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

@crynobone crynobone added needs more info More information is required stale labels Jan 13, 2025
@cedricblom
Copy link
Author

This issue can be closed. After researching the issue for over a day I figured that it was caused by a partner module. The "viaRelationship" query parameter and others were included in nova API requests. I wasn't aware that Nova itself does not include these parameters with API requests. Sorry for me opening this bug report in the first place and sorry for any inconveniences it may have caused.

@cedricblom cedricblom closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
@crynobone crynobone removed the needs more info More information is required label Jan 15, 2025
@laravel laravel locked as resolved and limited conversation to collaborators Jan 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants