Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

339
Views
Pase múltiples parámetros opcionales en Laravel 9

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' })}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!