0👍
You should do null checks when constructing the URL:
//vuejs in methods:
myFunction(id1, id2 = null) {
axios.post(`/api/model1/${id1}/model2${id2 ? `/${id2}` : ''}`)
.then((response) => {
console.log(response);
})
.catch(err => {
console.log(err);
});
},
You should also make the 2nd parameter optional:
Route::post('model1/{id}/model2/{id2?}', 'SomeController@doThis');
0👍
How making the your laravel route parameter as an optional :
Optional Parameter
Route::post('model1/{id}/model2/{id2?}', 'SomeController@doThis');
add the ?
at the model2
parameter.
Source:stackexchange.com