Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afoysal's avatar

Missing required parameter

I am trying to send AJAX request. My Route code is like below.

Route::group( ['prefix' => 'prayer', 'as' => 'prayer.'], function () {
     Route::resource( 'time', 'PrayerTimeController' );
});

My controller code is like below.

public function show($date,$month)
{
     // more code here   
}

My jQuery code is like below.

<script type="text/javascript">
    $('#prayer_date').change(function(e){
        var month = $('#prayer_month').val();
        var date = $(this).val();
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            url : "{{ route('vendor.prayer.time.show') }}" + '/' + date + '/' + month ,
            type : 'POST',
            dataType : 'json',
            success : function(result){
               alert('hello');
            }
        });
    });
</script>

I am getting error local.ERROR: Missing required parameter for [Route: vendor.prayer.time.show] [URI: mosque-panel/prayer/time/{time}] [Missing parameter: time].

0 likes
10 replies
Sinnbeck's avatar

If you dont plan to use resources as they are meant to be used, dont use them. As the resource is named 'time', it also expect that you pass in a model named Time $time in the show() method.. So just make up your own route

Route::get('time/{date}/{month}', 'PrayerTimeController@show');
1 like
afoysal's avatar

@Sinnbeck Thanks. Now my jQuery code is like below.

$('#prayer_date').change(function(e){
        var month = $('#prayer_month').val();
        var date = $(this).val();
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            url : "{{ route('vendor.prayer.time.show') }}"
            data: {month:month, date:date},
            type : 'POST',
            dataType : 'json',
            success : function(result){
               console.log(result);
            }
        });
    });

My route is like below.

Route::group( ['prefix' => 'prayer', 'as' => 'prayer.'], function () {
     Route::get( 'time/{date}/{month}', 'PrayerTimeController@show' );
     Route::resource( 'time', 'PrayerTimeController' );
});  

But still I am getting error local.ERROR: Missing required parameter for [Route: vendor.prayer.time.show] [URI: mosque-panel/prayer/time/{time}] [Missing parameter: time].

tykus's avatar

@afoysal the route helper for vendor.prayer.time.show expects a time parameter; you do not provide one:

route('vendor.prayer.time.show')

Your AJAX request is very confused because, as defined, this is a GET Route `, but you have the following AJAX options:

url : "{{ route('vendor.prayer.time.show') }}"
data: {month:month, date:date},
type : 'POST',

Maybe consider not using a resource Route?

1 like
afoysal's avatar

@tykus Thanks. Actually I am trying to solve the issue. I tried with get route. But I couldn't catch my issue. Could you please say where is the issue ? Could you please guide me ?

tykus's avatar

@afoysal what does the Controller action actually look like; what data are you retrieving?

1 like
afoysal's avatar

@tykus Thanks. Currently I would like to establish connection first. I would like to send $date & $month now.

afoysal's avatar

@tykus My controller function code is like below.

public function show($date,$month)
    {
        return $date;
    }
tykus's avatar
tykus
Best Answer
Level 104

@afoysal what I wondered was what might be returned from the Controller; do you fetch a Collection of times, or a single instance? I don't understand why you send a month and date - is the month different for some reason??

Route::group( ['prefix' => 'prayer', 'as' => 'prayer.'], function () {
     Route::get( 'times', 'PrayerTimeController' )->name('times');
});
// PrayerTimeController
public function __invoke(Request $request)
{
    $month = $request->get('month');
    $date = $request->get('date');

    // fetch data and return JSON response
}
$('#prayer_date').change(function(e){
        var month = $('#prayer_month').val();
        var date = $(this).val();
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            url : "{{ route('vendor.prayer.times') }}"
            data: {month:month, date:date},
            type : 'GET',
            dataType : 'json',
            success : function(result){
               console.log(result);
            }
        });
    });
1 like
afoysal's avatar

@tykus Thanks. Is there any { missing in this code ?

    $('#prayer_date').change(function(e){
        var month = $('#prayer_month').val();
        var date = $(this).val();
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            url : "{{ route('vendor.prayer.times') }}"
            data: {  month: month, date: date },
            type : 'GET',
            dataType : 'json',
            success : function(result){
               console.log(result);
            }
        });
    });

I am getting this error in console.

error

error

error

tykus's avatar

@afoysal there is a comma missing after the url value:

url : "{{ route('vendor.prayer.times') }}", // here
1 like

Please or to participate in this conversation.