TypeError: Cannot read property 'name' of undefined
See original GitHub issueDescription
Ziggy fails when you add parameters when they don’t exist.
Before version 1, I could just let the code be like this:
axios.post(route(endpoint, this.food.id), data)
.then(this.saved)
.catch(this.failed);
The endpoint is dynamically set. However, if you have URLs that don’t have parameters it now fails.
VM12 letscook:115 Uncaught (in promise) TypeError: Cannot read property 'name' of undefined
at VM12 letscook:115
at Array.reduce (<anonymous>)
at R.s (VM12 letscook:115)
at new R (VM12 letscook:115)
at VM12 letscook:115
at _callee$ (offerFood.js:21)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:274)
at Generator.prototype.<computed> [as next] (runtime.js:97)
at asyncGeneratorStep (CountryList.vue:45)
Expected behavior
It should work, even if the parameter is useless in some cases.
Current solution
// not that nice 😄
let url = '';
if (endpoint === 'uploadImage') {
url = route(endpoint);
} else {
url = route(endpoint, this.food.id);
}
axios.post(url, data)
.then(this.saved)
.catch(this.failed);
Environment
- Laravel version: v8.14.0
- Ziggy version: v1.0.1
Related routes:
Route::post('/upload/image', 'Api\ImageUploadController@store')->name('uploadImage');
Ziggy.routes
:
"uploadImage": {
"uri": "api\/upload\/image",
"methods": ["POST"]
},
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Uncaught TypeError: Cannot read property 'name' of undefined
This type of error mean that your container variable file is not defined. You should use console.log at different places to see what...
Read more >Uncaught TypeError: Cannot read property 'name' of undefined
It is a very common error when working with object and array to get a TypeError: Cannot read property 'name' of undefined ....
Read more >TypeError: Cannot read property 'name' of undefined #20
~/projects/xxx/frontend npm run start ✓ 4s > talan-frontend@1.1.0 start > vue-cli-service serve INFO Starting development server.
Read more >Cannot read property 'name' of undefined while using form ...
Getting TypeError: Cannot read property 'name' of undefined while using form-data ... This happens when some of the form value is undefined.
Read more >Cannot read property 'name' of undefined' mean? - Quora
Usually it means you misspelled a variable name, or forgot to declare a variable, or it is out of scope.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pmochine okay got it, thanks. I think I understand what’s happening, but I’m not sure that ignoring the extra param is actually the correct behaviour here. In an object, extra parameters are appended to the query string:
Laravel’s
route()
helper also works this way, except it can handle strings and arrays too:I agree that Ziggy should not error here, but rather than ignoring the params, I would actually expect it to append them to the query like this. What do you think? I know this doesn’t solve your problem, sorry! 🙃
Now that I suggested that I realize it’s not possible, since we’ve configured
qs
to filter out null query parameters… silently ignoring them might be the way to go after all! Still working on this, thanks for your patience.