I want to save the information from an form
HTML, in the database, through my CrudController
.
But I have not known how to do it, my variables form
are called the same as in my database and everything.
This is my file blade
.
<form method="POST" action="/save_design">
<input type="text" name="name" placeholder="Nombre del diseño">
<input type="submit" value="Guardar">
</form>
And I get a little confused about the routes, I don't know if I should consult in web.php
or in custom.php
. What I did in web.php
was the following:
<?php
Route::post('/save_design', 'DesignController@setupCreateOperation');
But I have errors, likeApp\Http\Controllers\Admin\DesignCrudController is not invokable.
In order to store the information that comes from your form I propose the following changes:
First in your error message I notice that you have this folder structure:
To achieve the above you must execute from the terminal:
Once that is done you will have the folder path mentioned above
Changing the path in your file
web.php
Code:
What I did:
Admin
in this case that contains it and a backslash\
name()
, this same name will be used to invoke it in theaction
formweb.php
stores your routes but is not the one you should callcontroller
must have at least these 2 methods:create
andstore
, wherecreate
it shows the form andstore
processes the data to store itI recommend editing the name of your method in the controller from: setupCreateOperation to store not only to improve its handling by having a simpler name but also to identify what operation we are doing
create
: What is used to show the registration form through the methodGET
store
: That will receive the data from the form with the help of the object$request
that helps us process the data of the requests by some HTTP verb and in this case it will bePOST
Modifying the code of your form
What I did was:
action
through the helperroute
@csrf
Now in the controller
It should look something like this:
What I did was:
store
$nuevoRegistro
I access->
the desired column by means of its namename
and later I obtain the value that I received from the form with the help of the object$request
input
through its name attribute, which in this case isname
save