Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

322
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda