Skip to content

Dynamically update outputted Ziggy JSON when using InertiaJS #566

@just-tom

Description

@just-tom

Ziggy version

1.4.6

Laravel version

9.9.0

Description

Hi!

Not necessarily a bug but more of a question. Im using Laravel, Vue, InertiaJS and Ziggy together and trying the utilise the URL::defaults method laravel provides with Ziggy adheres to.

My problem is if I want to update these default values in the @routes directive, I of course have to refresh the page. The issue with that is IntertiaJS doesnt refresh and effective acts like an ajax call.

Is there anyone that has effectively updated the routes dynamically based on Inertia Share or hooks or something along those lines?

I have seen the way to pull in the routes by an API call, but this negates the fact i'm trying to use defaults to make my code leaner as I would have to include Ziggy with each use of route()

For context I have a set of nested routes as such:

spaces/{space}/pages/{page}/sections/{section}/blocks
spaces/{space}/pages/{page}/sections/{section}/blocks/create
spaces/{space}/pages/{page}/sections/{section}/blocks/{block}
spaces/{space}/pages/{page}/sections/{section}/blocks/{block}/edit

So I am trying to use URL defaults to set the space id, page id, section id whenever your within that nested part of the application, rather than having to include the parameters with each route() call.

Open to any suggestions or ideas!

Thanks for your work guys

Ziggy call and context

@routes as standard at the moment. Then the `route()` helper elsewhere in my vue code

Ziggy configuration

{
  "defaults":{"space":"space123","page":"page123"}
}

Route definition

Route::resource('spaces', SpaceController::class);
Route::resource('spaces.pages', PageController::class);
Route::resource('spaces.pages.sections', SectionController::class);
Route::resource('spaces.pages.sections.blocks', BlockController::class);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions