Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 20, 2021 06:28 pm GMT

Laravel 8.0 CRUD Tutorial Using Mysql Database

Hello Artisan,

Today we will create a CRUD application in Laravel using Mysql Database. CRUD extends Create, Read, Update, Delete. We performing This operation in our new fresh laravel project. So, lets start.

Create a Laravel Project first, run this command

composer create-project --prefer-dist laravel/laravel blog

After completion the creation of laravel project, lets go

*Make databse Connection *
create a databse in the mysql database after that go to the .env file

and add the code

DB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=laravel_crudDB_USERNAME=rootDB_PASSWORD=

Set your Databasae name,username and password.

Now, run this command to migrate

php artisan migrate

Create Product model

php artisan make:model Product

Create migration for products table, run this command

php artisan make:migration create_products_table --create=products

lets add products table column propertise to the migration file.

Schema::create('products', function (Blueprint $table) {    $table->id();    $table->string('title');    $table->text('details');    $table->timestamps();});

Create Controller, run this command

php artisan make:controller ProductController --resource

In web.php add our route,

web.php

<?phpuse Illuminate\Support\Facades\Route;use App\Http\Controllers\ProductController;use App\Http\Controllers\UserController;/*|--------------------------------------------------------------------------| Web Routes|--------------------------------------------------------------------------|| Here is where you can register web routes for your application. These| routes are loaded by the RouteServiceProvider within a group which| contains the "web" middleware group. Now create something great!|*/Route::get('/', function () {    return view('index');});Route::resource('product',ProductController::class);

To see out all route, run this command

php artisan route:list

Output

FULL CRUD GET HERE: Link


Original Link: https://dev.to/jewelcse/laravel-8-0-crud-tutorial-using-mysql-database-4ecf

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To