Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Package seems abandoned #13

Open
RVxLab opened this issue Sep 1, 2020 · 6 comments
Open

Package seems abandoned #13

RVxLab opened this issue Sep 1, 2020 · 6 comments

Comments

@RVxLab
Copy link

RVxLab commented Sep 1, 2020

Forked here: https://github.com/webparking/nova-belongs-to-dependency

@pokono
Copy link

pokono commented Nov 18, 2020

The lack of response is worrisome..

@kjohnson
Copy link

I'll add that @RVxLab's recommendation worked for me, as it supports Laravel Nova 3.22.0

@garethnic
Copy link

Hey @RVxLab , @kjohnson - I'm on Laravel 8.42.0 and Nova 3.22.0 but on updating a resource with this field I end up getting Call to undefined method Illuminate\Database\Query\Builder::getQuery(). I did do the switch to https://github.com/webparking/nova-belongs-to-dependency
Do you guys have any suggestions on where I could start poking around to resolve this?

@garethnic
Copy link

garethnic commented May 19, 2021

Moving to 3.19.0 results in
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'key' in 'where clause' (SQL: select * from `outdoor_types` where `outdoor_types`.`deleted_at` is null and `key` = 40 order by `outdoor_types`.`id` desc limit 1)

That 'key' should be outdoor_types`.`id

@alberto-bottarini
Copy link
Contributor

I changed

return $query->where($this->meta['dependsOnKey'], $request->dependsOnValue);

with

return $query->tap(function ($query) use ($request) {
  return $query->where($this->meta['dependsOnKey'], $request->dependsOnValue);
});

in Manmohanjit\BelongsToDependency\BelongsToDependency and it seems to work

@garethnic
Copy link

garethnic commented May 21, 2021

Thanks for that. My approach was to copy all the source as a local nova component and add the following into BelongsToDependency.php:

Changed the buildAssociatableQuery function to:

public function buildAssociatableQuery(NovaRequest $request, $withTrashed = false)
    {
        $returnable =  parent::buildAssociatableQuery($request, $withTrashed);
        $query = $returnable->toBase();

        if ($request->has('dependsOnValue')) {
            $query->where($this->meta['dependsOnKey'], $request->dependsOnValue);
        }

        return $returnable;
    }

And overriding the getRules function by pulling it in:

public function getRules(NovaRequest $request)
    {
        $query = $this->buildAssociatableQuery(
            $request, $request->{$this->attribute.'_trashed'} === 'true'
        );

        return array_merge_recursive(parent::getRules($request), [
            $this->attribute => array_filter([
                $this->nullable ? 'nullable' : 'required',
                new Relatable($request, $query->toBase()),
            ]),
        ]);
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants