Laravel got route list issue

111 views Asked by At

I am getting this error:

Error: Ziggy error: route 'contract/generatePDF?id=517&pickupKM=0' is not in the route list.

but is defined in the web.php: GET|HEAD contract/generatePDF

Route::get('contract/generatePDF', [App\Http\Controllers\ContractController::class, 'generatePDF'])->name('contract.generatePDF');

and from the vue I am calling this function:

router.visit(route("contract/generatePDF?id="+props.contract.id+"&pickupKM="+pickupKM));

also tried like this:

router.visit("/contract/generatePDF?id="+props.contract.id+"&pickupKM="+pickupKM);
2

There are 2 answers

7
ceejayoz On

Ziggy expects a route name that matches one of your Laravel-side routes. Query parameters are passed separately; they are not part of the route's name.

https://github.com/tighten/ziggy#query-parameters

route('contract.generatePDF', {
    id: props.contract.id,
    pickupKM: pickupKM
});

Your issue is two-fold; you're giving Ziggy the route's URL (contract/generatePDF) instead of its name (contract.generatePDF), and you're including the query string in the name, which Ziggy doesn't automatically parse out for you.

1
Vannian On

I found the issue. Somehow the word contract is the cause of it. I have already defined

Route::resource('contract', ContractController:class) 

And then I defined this

Route::get('contract/generatePDF', ContractController::class) 

and getting 404.

I just changed the order and is working:

Route::get('contract/generatePDF', [ContractController::class, 'generatePDF'])->name('contract.generatePDF');
Route::resource('contract', App\Http\Controllers\ContractController::class);