Part 10 - CRUD and RESTful Routes [How to Build a Blog with Laravel 5 Series]

276 views

0   0


Before moving on to create our posts controller we must first explore something fundamental to all programming and that is CRUD. Crud is used to manage resources which are the main parts of all applications. Just take a moment to think about your next great app idea. It involves managing a resource at its core. Maybe they are tasks, statuses, photos, or posts. The web app is simply a way to create new resources, edit existing ones, delete them or view them.

CRUD Stands for:

C = Create
R = Read
U = Update
D = Delete/Destroy

With these 4 simple actions we can manipulate our resources as much as we want.

Now it is time to learn more about how we use these in our application. First we should make a controller to handle this resource. Just like last time, we will create a controller, but this time, we will let Artisan do the hard work for us. In our terminal we will type in the command

php artisan make:controller PostController --resource

This tells artisan to make a controller, but not any controller, a resource controller and give it the name PostController. This controller is a special controller designed to allow us to perform CRUD operations on our resource.

Because CRUD is so common, not only does Laravel give us an easy command to create a CRUD controller, but they also give us a command to make CRUD routes as well. These are sometimes called RESTful Routes, but are exactly the same. The code to do this is in the code snippets below.

Laravel is very handy and allows us to create all the CRUD routes with one command. To see all the work behind the scenes we can display the routes available to us (and see all the commands that Laravel gave us with the Route::resource helper. We can view these by going to terminal and typing in a command to view all our routes. We can see that Laravel now expects these RESTful routes.

Coming Up:
We will be making the create() function working so we can fill out a form to make a blog post.

--- CODE SNIPPETS ---

Create Controller (in Terminal.app)
php artisan make:controller PostController --resource

Automatic CRUD/REST Routes (in app/http/routes.php)
Route::resource('posts', 'PostController');

List All Routes (in Terminal.app)
php artisan route:list

--- MORE FROM THIS SERIES ---

Previous Video [Part 9]: https://youtu.be/pR9frREjwDY
Next video [Part 11]: https://youtu.be/El4yziFuygQ

Full Playlist for the "How to Build a Blog with Laravel" Series: https://www.youtube.com/playlist?list...

--- FOLLOW ME ---

Subscribe for New Releases!

Twitter - http://twitter.com/_jacurtis
(ask me questions!)

--- QUESTIONS? ---

Leave a comment below and I or someone else can help you.
For quick questions you may also want to ask me on Twitter, I respond almost immediately.

Thanks for all your support!

---

Tags: Laravel 5.2 Framework Tutorial Easy to learn. Best tut about Laravel. Build a blog with Laravel Tutorial. Beginner tutorial. How to video. PHP framework easy best tutorial. Laravel 5 coding in PHP with Alex.

Published 11 months ago

Category Video  /  Video aulas

Tagsphp laravel code blog app web tutorial crud rest

View More
Comments

0 Comments