I am trying to create a route that takes either one of two parameters. However the dd returns me $b_id, null
instead of null, $b_id
. How can I pass only b as a parameter and omit a?
web.php
Route::get('myroute/{a?}/{b?}', [MyController::class, 'testFunction'])
->name('test.testFunction');
Controller
public function testFunction( $a = null, $b = null)
{
dd($a, $b);
// stuff
}
Ajax call
function test($b_id) {
$url = "{{ route('test.testFunction', ':b') }}";
$url = $url.replace(":b", $b_id);
$.ajax({
url: $url,
type: 'GET'
})}