0

I want to pass the 'CourseId' variable from a page view to a controller in order to delete it, but not sure why I can't access the variable:

view:

this.$inertia.get(this.route('applications.courseDelete', CourseId ))

route:

Route::get('applications/courseDelete', [ApplicationsController::class, 'courseDelete'])->name('applications.courseDelete')->middleware('auth');

controller:

public function courseDelete($courseId)
{        
   dd($courseId);
}

this returns the error, 'too few arguments...'. ive tried adding the model here also, but returns a blank array. sure i'm missing something very obvious here?

3
  • 1
    you need to procive id in your route Route::post('applications/courseDelete/{courseId}', [ApplicationsController::class, 'courseDelete'])->name('applications.courseDelete')->middleware('auth'); also change it to post or delete not get in order to send variable Commented Jul 26, 2021 at 11:03
  • thanks @mafortis, also, using the same method, can i pass multiple variables? (this.route('applications.courseDelete', CourseId, UserId ? Commented Jul 26, 2021 at 12:12
  • 1
    yes you can pass as much variable as you like. Commented Jul 26, 2021 at 12:16

1 Answer 1

1

Since you didn't provide the method in which you call the get request, I'm guessing you just need to do something like this because you are calling the CourseId from data().

this.$inertia.get(this.route('applications.courseDelete', this.CourseId ))

Also you need to pass the variable through your route so also change this

Route::get('applications/courseDelete/{CourseId}',
    [ApplicationsController::class, 'courseDelete']
)->name('applications.courseDelete')->middleware('auth');
Sign up to request clarification or add additional context in comments.

1 Comment

for anyone that wants to pass multiple parameters: this.$inertia.get(this.route('applications.courseDelete', [CourseId, UserId] )) - Route::delete('applications/courseDelete{courseId}/{userId}... - public function courseDelete($courseId, $userId)

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.