CRUD is an short form for Create, Read, Update, and Delete. Using this operation users can easily manipulate the data.
To preform CRUD operation we have to preform certain steps :
Step 1 : Make a new Project .
To create a new project, run the following code in Git Bash in C:/xamp/htdocs Folder:
composer create-project –prefer-dist laravel/laravel project_name “version_name.*”
Eg: composer create-project –prefer-dist laravel/laravel Employees “5.8.*”
It will automatically install all the necessary file and folder for you.
Step 2 : Create a Database in SQL
Run Xamp Controller and start Apache and MySQL.
Search localhost/phpmyadmin in your browser
Create a new database using MySQL by simply click in New button and give your database a unique name.
Step 3 : Modify the Database connection in .env File
Open the .env file and change database name and set username to “root”.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= your database name
DB_USERNAME=you username(Default: root)
DB_PASSWORD=
Step 4: Link the project with database
To link database run the following command on Command Promt/Git Bash/Vs Code Terminal:
php artisan migrate
Step 5: Create Table in database
We are going to create crud application for product. so we have to create migration for “products” table using Laravel 5.8 php artisan command
php artisan make:migration create_products_table –create=products
Step 6: Migration
Step 7: Create Blade File
Go to Project_name/resources/views and create the following file:
i . parent.blade.php
ii. create.blade.php
iii. view.blade.php
iv. edit.blade.php
v. index.blade.php
Step 9 : Set Route
Go to Project_name/route/web.php add the following code to change the route to universal route
We can easily change the route by changing the route name.
- Using Role Based Authentication, Create Different Users DashBoard - March 22, 2021
- CRUD Operation Using Laravel - March 20, 2021