Estoy tratando de crear una ruta que tome uno de dos parámetros. Sin embargo, el dd me devuelve $b_id, null en lugar de null, $b_id . ¿Cómo puedo pasar solo b como parámetro y omitir a?
web.php
Route::get('myroute/{a?}/{b?}', [MyController::class, 'testFunction']) ->name('test.testFunction');Controlador
public function testFunction( $a = null, $b = null) { dd($a, $b); // stuff }llamada ajax
function test($b_id) { $url = "{{ route('test.testFunction', ':b') }}"; $url = $url.replace(":b", $b_id); $.ajax({ url: $url, type: 'GET' })}Esto no es realmente posible en este momento, pero hay una solución. Puede pasar los parámetros en una matriz con nombre y cambiar la ruta a simplemente Route::get('myroute' ...) :
route('test.testFunction', ['a' => 'xyz', 'b' => 'yzt']) ===== creates http://myroute?a=xyz&b=yzt Luego puede verificar si los parámetros a o b están presentes y recuperarlos normalmente si lo están.