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

321
Views
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 answers
Answer question

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 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!