Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel difference between resource.create and resource.store

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,

like image 338
user2722667 Avatar asked Nov 16 '14 14:11

user2722667


People also ask

What is Apiresource in Laravel?

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.

How do you make a resource controller in Laravel?

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.

What is a controller in Laravel?

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.

Is Laravel restful?

Laravel provides a convenient way to create Restful APIs via resourceful controllers. Create a route for the resourceful controller in routes/api.


3 Answers

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.

like image 99
itachi Avatar answered Oct 05 '22 23:10

itachi


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).

like image 27
MANOJ Avatar answered Oct 06 '22 00:10

MANOJ


resource.create = Frontend

resource.store = Backend

like image 21
14714 Avatar answered Oct 06 '22 01:10

14714