Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Bacherino's avatar

How to pass laravel variable to ajax post in update method ?

I'm trying to use update method with ajax, but unfortunately i couldn't get it how should i pass multiple laravel variable to the ajax while i want to use resource controller's update method.

0 likes
8 replies
Sinnbeck's avatar

You can send extra data to a put method without any problem. Can you show the code for your ajax request?

1 like
Bacherino's avatar

@Sinnbeck I'm trying to update my column on page load with ajax update so basicly when the time has come it should be update the data on database and for ex. change the activity from 1 to 0. But i have thousands of data to do that.

Bacherino's avatar

I want to pass that course_id to the ajax url how should i do that ?

var course_id = $(this).attr('course-id');
 $.ajax({
                type: "PUT",
                url: {{ route('courses.update',course_id ) }},
                data: {
                    course_id : course_id,
                }
});
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Bacherino Be aware that this wont work, as php is rendered before javascript. So php knows nothing about course_id

url: {{ route('courses.update',course_id ) }},

Instead you will need something like

url: '/courses/' + course_id,
1 like

Please or to participate in this conversation.