DEV Community

Rohit Urane
Rohit Urane

Posted on

Mastering Efficiency: Unleashing the Power of CRUD Operations in Laravel

Image description

To manage structured data efficiently by providing the functionality to Create, Read, Update, and Delete records. In this article, We are studying the crud operations in laravel 9 with examples and validating user inputs in laravel.

Create a project on Laravel

Run the below command to create a laravel application.

composer create-project --prefer-dist laravel/laravel:^9.0 laravel-crud
Enter fullscreen mode Exit fullscreen mode

Update the env file

Update the database credentials in the .env file.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database-name
DB_USERNAME=user-name
DB_PASSWORD=password
Enter fullscreen mode Exit fullscreen mode

Make a Model and Migration

We are storing information on the database. For that, we make a migration and model using the below command.

php artisan make:model Contact -m
Enter fullscreen mode Exit fullscreen mode

Now, you can check /database/migrations directory. Update the current generated file like below.

public function up()
{
     Schema::create('contacts', function(Blueprint $table){
             $table->id();
             $table->string('name');
             $table->string('email');
             $table->string('mobile');
             $table->timestamps();
     })
}
Enter fullscreen mode Exit fullscreen mode

You can read More details on https://bit.ly/3tlEgXi

Top comments (0)