The resource in Laravel creates methods for performing CRUD.
Methods are used to list, update, display, create, and delete records.
For example, if you create a resource for UsersController, you should have the methods index (get)
, create (get)
, store (post)
, edit (get)
, update (put)
, destroy (delete)
.
I want to create a new record in the database, should I use the POST verb to call the action store?
Yes, the resource method equivalent to the "create" action is store
. The HTTP request method required is POST.
The create
method is just the interface for creation, so it's a GET method.
I want to update an existing registry in a database, should I use that verb, the action will be store or update?
It should be update
. The update
method requires a request of type PUT
. It is important to note this, because if you are using a request of type Ajax
, you will need to specify this method.
If I am right, action update and destroy should be used to manipulate files in the file system. Is that right?
Not necessarily a file system. The resource actually aims to make it easier to create a CRUD based on REST, where you have each url responsible for an action.
Generally, you use Laravel update
to update a record, and destroy
, to remove.