Skip to content

How to use the plugin #12

Answered by jameswagoner
MathieuB27 asked this question in Q&A
Jun 23, 2022 · 3 comments · 2 replies
Discussion options

You must be logged in to vote

You are correct that have to build your navigation inside of $this->app->booted() callback if you want to to use a service provider.

Alternatively, you could build your navigation in a middleware. This was my approach since I am using Inertia and used the HandleInertiaRequests middleware.

public function share(Request $request)
{
    return array_merge(parent::share($request), [
        'navigation' => $this->buildNavigation()->tree()
    ]
}

protected function buildNavigation()
{
    return app(Navigation::class)->addIf(
        auth()->user()->can('manage'),
        'Users',
        route('users')
    );
}

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@freekmurze
Comment options

@MathieuB27
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by freekmurze
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants