Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

328
Vistas
Laravel perform route action on select dropdown onchange, create specific URL

I've got Dropdown select with the list with future 12 months:

<select name="month" id="specificMonth">
    @foreach(Carbon\CarbonPeriod::create(now()->startOfMonth(), '1 month', now()->addMonths(11)->startOfMonth()) as $date)
        <option value="{{ $date }}">
               {{ $date->format('F Y') }}
        </option>
    @endforeach
</select>

If the option in dropdown changes, I want to perform route action like:

 $('#specificMonth').change(function(){
            var data = $(this).serialize();
            alert(data);

            $.ajax({
                type: "POST",
                URL: "{{ route('calendar.specificMonth', 'date') }}",
                data: data,
                success: function () {
                    console.log("works");
                }
            });
       });

So I need to get the selected month in Controller and return view with specific month. How I can do that?

When I "alerts" data it shows it correctly.

URL in my case should look like:

/calendar/{date}

Or something like that. For now my route for that looks like:

Route::post(
    '/calendar/{date}',
    [CalendarController::class, 'specificMonth']
)->name('calendar.specificMonth');

But performing an action in view gives me an error "POST http://127.0.0.1:8000/calendar 405 (Method Not Allowed)".

This should be POST or GET method? How to create custom URL in that case?

Updated, Method from Controller in which I want to dump data only:

public function specificMonth(Request $request, $date)
    {
        dd($request);
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You cannot dump data while using ajax. You can use Illuminate\Support\Facades\Log::debug($request) in the controller. Then the request will be shown in the storage/logs/logfielname.log.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda