2

How can I pass the route param while using Inertia manual visit, for example:

Route:

Route::post('/explore/gallery/like/{$post}', [ExploreController::class, 'likeToggle'])
    ->name('explore.post.like');

Component:

Inertia.visit(route('explore.post.like'),
                {
                    method: 'post',
                    preserveScroll: true,
                    data: {
                        $post: this.id
                    },
                },
            );

but is shows the error tho,

enter image description here

2 Answers 2

2

Error occur in Ziggy, and says you need pass $post,

Ok, Change route('explore.post.like') to route('explore.post.like', this.id)

According Ziggy documentation you can also use like :

route('explore.post.like', this.id)
route('explore.post.like', [this.id])
route('explore.post.like', { $post: this.id })
Sign up to request clarification or add additional context in comments.

1 Comment

Thx for your answer.
2

A simple solution would be:

Inertia.post(route('explore.post.like', [this.id, 'if you have other params']), {}, {
                preserveScroll: true,
            });

Pls make sure the order is correct, follow the order of your route's param

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.