I am about to learn about building RestFul apps in Laravel but I dont understand the difference between resource.create and resource.store
If I want to register and create a new user, does it then use resource.create or resource.store ?
If not, when to use resource.create ? And when should I use resource.store ?
Cheers,
Laravel's resource classes allow you to expressively and easily transform your models and model collections into JSON. Basically you can generate a nice json formatted data right from Eloquent.
Creating the Controller This is the easy part. From the command line in the root directory of your Laravel project, type: php artisan make:controller sharkController --resource This will create our resource controller with all the methods we need.
A Controller is that which controls the behavior of a request. It handles the requests coming from the Routes. In Laravel, a controller is in the 'app/Http/Controllers' directory. All the controllers, that are to be created, should be in this directory.
Laravel provides a convenient way to create Restful APIs via resourceful controllers. Create a route for the resourceful controller in routes/api.
just a simple example. (oversimplification)
let's say you are writing a blog.
the GET
request you are sending to get the form (where you will write the blog) is resource.create
.
after finishing the writing, when you will submit and POST
the content so that it gets saved in somewhere, it is resource.store
in your case,
registration form
is resource.create
.
saving the info (submitting the form) is resource.store
.
resource.create
shows the form for creating a new resource (front end only to show the form) and resource.store
stores a newly created resource in storage (db interaction to store the data).
resource.create
= Frontend
resource.store
= Backend
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With