Naim R.
Naim R.

Reputation: 183

How to support a laravel route with "?" in url instead of "/"?

I have the following form tag :

< form action="../resume?jobs={{$jobs->job_id}}" method="post" enctype="multipart/form-data">
@csrf
//remaining of the code

The question is how to support this route in web.php?

I tried below but not working :

Route::post('/resume/{?jobs}', function ($jobs) {
......
}

As you notice I want the url to have parameters and not backslash at the end, example: http://127.0.0.1:8000/resume?jobs=1211

Thanks for help.

Upvotes: 1

Views: 492

Answers (1)

Peppermintology
Peppermintology

Reputation: 10210

You don't need to cater for query string parameters in your routes, they will be available to you in the Request object.

// route for /resume?jobs=123
Route::get('/resume', function (Request $request) {
    $job_id = $request->query('jobs'); // 123
})->name('resume');

Then in your view, all you need to do is call the route helper.

<form action="{{ route('resume', ['jobs' => $jobs->job_id]) }}" method="POST" enctype="multipart/form-data">

The first parameter of route is the name of the route, from the routes/web.php file.
The second parameter is all your variables. If the URI doesn't have any parameters, then they will automatically be appended as a query string.

Upvotes: 3

Related Questions