Website Programming CRUD PHP Framework Laravel – Part 2

Tram Ho

Working with Route, Controller and Model will be introduced in this section. Building a CRUD users project with Laravel 5.5. Website Programming CRUD using PHP Framework Laravel.

We will continue with setting up the Route, Controller, Model and View in the PHP Framework Laravel 5.5 CRUD users project.

Step 5: Create the UserController

Use the following command in Terminal to create the UserController:

The command to create the Controller will create the UserController.php file under the path user-crud-laravel / app / Http / Controllers / UserController.php. The –resource flag helps us create 7 functions with names according to the conventional CRUD Laravel standard. The UserController.php file will have the following source code:

Each function has a specific task, for example index – display all users, destroy – delete specific users, …

Step 6: Create a Route to handle CRUD

Search for web.php file by following user-crud-laravel / routes / web.php and edit the following:

The static function resource defined above will give us 7 routes and point specifically to the 7 functions in the UserController. Use the following command to view the entire route of the PHP Framework Laravel project in Terminal:

In addition to the first 2 routes created by Laravel, the remaining routes are created by the static function resource of the above Route class.

Step 7: Create a Model User

By default, Laravel has created our User model, we temporarily delete this model to become familiar with the Model creation command. Find the file User.php under the path user-crud-laravel / app / User.php. Use the following command in Terminal / GitBash to create a Model User:

We have Migration, Seeder, Route, Controller and Model for Laravel 5.5 CRUD project. The next part I will introduce about View is Logic following the standard MVC architecture in Laravel 5.5.

Share the news now

Source : Viblo