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

Nesting of models #29

Open
martin-ro opened this issue Jun 4, 2020 · 0 comments
Open

Nesting of models #29

martin-ro opened this issue Jun 4, 2020 · 0 comments

Comments

@martin-ro
Copy link

martin-ro commented Jun 4, 2020

Hi,

I was thinking if it would make sense to introduce model nesting a bit differently.
As far as I understand it is possible to mimic the default Laravel behavior like assigning one model as the unique parent e.g. /jobs/frontend-web-developer.

How would I go about a scenario where a model can be parent to multiple other models and vice versa?

I would like to nest a page model something like this:

-Page 1 {page-1}
--Page 2 {page-1/page-2}
----Page A {page-1/page-2/page-a}
--Page 3 {page-1/page-3}
-Category A {category-a}
--Page 4 {category-a/page-4}
----Page 5 {category-5/page-4/page-5}
--Page 6 {category-a/page-6}
-Page 7 {page-7}
--Category A {page-7/category-a}

One issue is the restriction that parent_for must be unique. I was thinking with a pivot table using parent id, child id and entity type this could be solved?

Having the model id, entity type and all it's children the slugs still could be recursively updated I think.

Any thoughts on that or a better way to achieve that sort of nesting?

*Something else: what is the reason you check $permalink->getOriginal('slug') !== $permalink->slug?

/**
     * Updating event.
     *
     * @param $model
     */
    public function updating($permalink)
    {
        if ($permalink->getOriginal('slug') !== $permalink->slug) {
            $this->ensureSlugIsUnique($permalink);

            config('permalink.rebuild_children_on_update')
                ? $this->path->recursive($permalink)
                : $this->path->single($permalink);
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant