Skip to content
Advertisement

store function laravel 8 not saving data to the database

Thanks in advance for taking the time to read throw the question.

so I have a form in a blade view where a user can add a name, a description, and upload an image but the data is not being passed to the database

The blade view:

JavaScript

store function in controller :

JavaScript

The migration which I had used:

JavaScript

and at last the route which I’m using is:

JavaScript

did I miss anything in the previously mentioned code?

Advertisement

Answer

You’re missing 2 things on your form:

method='POST' — this tells the form to actually submit the form as a POST request and not a GET request

@csrf — All Laravel forms must have a CSRF token to be accepted, unless it is explicitly bypassed in the middleware or submitted via GET, such as a search form

edit

Also for file uploads, you need to add enctype="multipart/form-data" to your form.

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