Skip to content
Advertisement

Form data isn’t submitting to database in Laravel controller

In my home page in my Laravel project I have a modal which contains a form.

JavaScript

And of course in my web.php file I’ve made a route like so:

JavaScript

It’s referring to the function in my ProfilesController that should take the data from the form and save it to my database.

JavaScript

The $user variable should be getting the authenticated (logged in) user in the database. The purpose of this all is that so they can submit a bio and URL that will eventually be put on their profile but for now It’s just being put into the ‘bio’ and ‘profileurl’ columns in the table.

However when I submit the form it adds nothing. Notably, it’s saying that “save()” is an undefined method which is odd because it only gets caught as an error when I define $user as “Auth::user();”. Any help?

Advertisement

Answer

You need to add name attribute for each <input/>

Only form elements with a name attribute will have their values passed when submitting a form.

Also add {{ csrf_field() }} for AntiCSRF

here I’ve rewritten your code.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement