Laravel 5.8 CRUD operation with example

In this tutorial we will learn how we can create a project in CRUD (Create, Read, Update and Delete) operations through Laravel. We will get to know how to create, update read and delete in Laravel from Scratch.

Initially have to download Laravel 5.8 version. For this you have to go to command prompt, in which first we have go to our folder path in which we want to download Laravel 5.8. After this we have to run “composer” command, because all Laravel depository is handled by composer. After run “composer” command we have to run following command:

composer create-project laravel/laravel=5.8 crud --prefer-dist

After downloading Laravel 5.8, we have to make Mysql database connection from Laravel 5.8.

We have to find .env file in your Laravel 5.8 folder. Open that file and under we have to define our mysql database before that we have to create a database in our mysql named as ‘crud’ and then we have to configure our .env as given below.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=crud
DB_USERNAME=root
DB_PASSWORD=

After this we have to create migration file in our Laravel folder. For this we have to write following command in your command prompt.

php artisan make:migration create_crud_table --create=crud

This command will create migration file in database/migrations folder. In this file we have to define table column which we want to create in table. Below we can find migration file in which we have define table column.

Now we want to migrate this table definition from this Laravel application to mysql database. For this we have write following command in command prompt. This command will make crud table in mysql database for perform CRUD operation from Laravel 5.8 application.

php artisan migrate

Now we have to create model for our database which is used for operations in controller class. To create a model we will run the command given below.

php artisan make:model Crud -m

This command will make Crud.php model file in app folder. In this file we have to define table column name which we can see below source code of Crud.php file.

Now we have to create Laravel 5.8 crud controller. For this we have to go to command prompt and under this we have write following command.

php artisan make:controller CrudsController --resource

This command will make CrudsController.php file in app/Http/Controllers folder. Once we open this file, we can find all predefine method for do CRUD operation in this controller file. We have to just add code for doing particular operation. Below we can find CRUD controller file code.

Now we have to set route of all CrudsController class method. For this we have to open to routes/web.php file. In this file we have to write following code for set route of all method.

Route::resource('crud','CrudsController');

Now in this step we have to set data in view file which has been store under resources/views folder, because this view file has received data from controller method, so here we have to set data in view file. Below we can find all view file which has been used in Crud application, and we can also find how data has been set and how to make form in Laravel 5.8 view file.

Now we can run the Laravel 5.8 Crud application, for this we have to go to command prompt, and write following command.

php artisan serve

For reference you can see the video given below:

Joydeep M
Latest posts by Joydeep M (see all)
Tagged :
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x