This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Perform CRUD (Create, Read, Update, Delete) Operations in Laravel

Updated on January 22, 2026

16 Min Read

Key Takeaways

  • Laravel’s Eloquent ORM performs complex database operations with minimal, expressive code.
  • Resource Controllers automatically generate all standard CRUD routes and methods for you.
  • Blade templating simplifies building dynamic layouts without complex frontend frameworks.
  • Git-based workflows ensure secure, consistent deployments from local to production.

Effective data management is the primary challenge in building dynamic web applications. Without a structured framework, handling database records becomes repetitive, difficult to maintain, and prone to security vulnerabilities like SQL injection.

To solve this, developers rely on CRUD (Create, Read, Update, Delete) operations to standardize how applications interact with databases. Laravel streamlines this process through its Eloquent ORM, allowing you to interact with your database using expressive, object-oriented syntax rather than complex raw SQL.

In this guide, we will build a complete “Product Management” application using Laravel 11. We will cover the entire development lifecycle, including:

  • Configuring the Database and running Migrations.
  • Building Controllers to handle business logic.
  • Designing the User Interface (UI) with Blade Templates.
  • Implementing strict validation for data integrity.

By the end of this tutorial, you will have a fully functional application. To help you follow along, I have provided the complete source code in a GitHub Repository. You can reference this code as you build, or deploy it directly to a Cloudways Free Trial to see your project in action on a live server.

What Are CRUD Operations in Laravel?

CRUD stands for Create, Read, Update, and Delete. These are the four fundamental operations required to manage data in any persistent storage system, such as a relational database like MySQL or MariaDB.

In the context of Laravel, these operations don’t just interact with the database; they map directly to HTTP verbs (routes) and Eloquent ORM methods. Understanding this mapping is key to building RESTful applications.

Here is how CRUD operations translate from user actions to Laravel code:

Operation Purpose SQL Command HTTP Verb Laravel Method
Create Add new data INSERT POST Model::create()
Read Retrieve data SELECT GET Model::all()
Update Modify existing data UPDATE PUT / PATCH $model->update()
Delete Remove data DELETE DELETE $model->delete()

Laravel simplifies these interactions using the Eloquent ORM, allowing you to work with PHP objects instead of writing raw SQL queries. This makes your code cleaner, safer, and easier to maintain.

Stop Configuring Servers. Start Coding.

Don’t waste hours wrestling with Nginx, PHP versions, and MySQL configs. Launch a pre-optimized Laravel server in 1 click so you can focus on building your app.

System Requirements for CRUD

To perform CRUD operations in Laravel 11, ensure your environment meets the following requirements. If you use Cloudways, these are ready to go:

  • PHP: Version 8.2 or higher.
  • Laravel: Version 11.x.
  • Composer: The PHP dependency manager (Required).
  • Node.js & NPM: Required for compiling assets (Vite).
  • Database: MySQL or MariaDB.
  • Web Server: Apache or Nginx.

Step 1: Install Laravel and Create a New Application

We will start by creating a fresh Laravel 11 application. Open your terminal (Command Prompt or PowerShell on Windows) and navigate to the folder where you keep your projects (e.g., htdocs if using XAMPP, or just your Desktop).

Run the following command to download and install Laravel. We will name our project product-app:

composer create-project laravel/laravel:^11.0 product-app

Run the command to download and install Laravel

Once the installation finishes, navigate into the project directory:

cd product-app

Now, start Laravel’s built-in development server. This allows us to preview the app without configuring Apache manually:

php artisan serve

You will see a message saying Server running on [http://127.0.0.1:8000]. Open that URL in your browser. If you see the Laravel splash screen, you are ready to proceed.

Laravel splash screen

Step 2: Create and Configure the Database

Before writing code, we need a place to store our data. Since we are using a local environment to create our project, we can use phpMyAdmin to create the database. For this tutorial, I’ll use XAMPP.

1. Create the Database

  • Open your XAMPP Control Panel and ensure MySQL is running.
  • Open your browser and go to http://localhost/phpmyadmin.
  • Click on the Databases tab (or “New” in the sidebar).
  • In the “Database name” field, type: laravel_crud.
  • In the dropdown next to the name (Collation), select utf8mb4_unicode_ci.
  • Click Create.

database created for laravel crud project

You now have an empty database. Do not create any tables manually—Laravel will do that for us automatically in the next step.

2. Connect Laravel to the Database

Now you need to tell Laravel to use the new database.

Open your project folder and locate the .env file inside it. Use any code editor or text editor to open the file. You can use Notepad if you prefer.

Find the database configuration variables and update them to match your local setup:

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

Find the database configuration variables and update them to match your local setup

Tip: If you set a root password for MySQL in XAMPP, enter it in the DB_PASSWORD field. Otherwise, leave it blank.

Step 3: Create the Model and Migration

In Laravel, we rarely create tables using SQL commands. Instead, we use Migrations (blueprints for tables) and Models (PHP classes to interact with those tables).

Run the following command to generate a Model named Product and a Migration file at the same time (using the -m flag):

php artisan make:model Product -m

1. Define the Table Structure

This command created a new file in database/migrations/ ending in _create_products_table.php. Open this file.

open the newly created migrations file

We need to define what data a “Product” has. Update the up() function to look like this:

public function up(): void
{
    Schema::create('products', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->text('description');
        $table->decimal('price', 8, 2);
        $table->timestamps();
    });
}

This structure sets up a products table with an ID, name, description, price, and timestamp columns.

2. Run the Migration

Now, run the migration command. This tells Laravel to look at the file we just edited and actually create the table in your MySQL database.

php artisan migrate

run migrations

If you check phpMyAdmin now, you will see a new products table has been created automatically!

products table created in phpmyadmin

3. Configure the Model

Open the file app/Models/Product.php. By default, Laravel protects your database from “Mass Assignment” vulnerabilities. We need to explicitly tell Laravel which fields are safe to save.

Add the $fillable property inside the class:

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'description',
        'price'
    ];
}

This allows Laravel to safely save product name, description, and price values.

Step 4: Create the Controller

The Controller is the “brain” of the operation. It handles the logic: fetching data, validating forms, and saving inputs.

Run this command to create a controller with all the standard CRUD methods built-in:

php artisan make:controller ProductController --resource

Open app/Http/Controllers/ProductController.php. We will now implement the logic for each step.

Important: First, add the Product model and the RedirectResponse class at the top of the file so we can use them:

use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Http\RedirectResponse;

Once these are added, you can implement the CRUD logic inside the class. Let’s do that now…

1. The Index Method (Read)

This fetches the latest products from the database (5 per page) and sends them to our view.

public function index(): View
{
    $products = Product::latest()->paginate(5);
    return view('products.index', compact('products'));
}

2. The Create Method (Show Form)

This simply loads the HTML form where users can input a new product.

public function create(): View
{
    return view('products.create');
}

3. The Store Method (Save Data)

This receives the form data. It validates that the inputs are not empty, creates the product, and then redirects the user back to the list.

public function store(Request $request): RedirectResponse
{
    $request->validate([
        'name'        => 'required',
        'description' => 'required',
        'price'       => 'required|numeric',
    ]);

    Product::create($request->all());

    return redirect()->route('products.index')
                     ->with('success', 'Product created successfully.');
}

4. The Show Method (Read One)

This displays the details of a specific product.

public function show(Product $product): View
{
    return view('products.show', compact('product'));
}

5. The Edit Method (Show Edit Form)

This finds a specific product and sends its current data to an “Edit” form so the user can modify it.

public function edit(Product $product): View
{
    return view('products.edit', compact('product'));
}

6. The Update Method (Save Changes)

This validates the updated data and saves the changes to the database.

public function update(Request $request, Product $product): RedirectResponse
{
    $request->validate([
        'name'        => 'required',
        'description' => 'required',
        'price'       => 'required|numeric',
    ]);

    $product->update($request->all());

    return redirect()->route('products.index')
                     ->with('success', 'Product updated successfully.');
}

7. The Destroy Method (Delete)

This deletes the product from the database.

public function destroy(Product $product): RedirectResponse
{
    $product->delete();

    return redirect()->route('products.index')
                     ->with('success', 'Product deleted successfully.');
}

Here is my final complete file:

<?php

namespace App\Http\Controllers;

use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;

class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index(): View
    {
        $products = Product::latest()->paginate(5);
        return view('products.index', compact('products'));
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create(): View
    {
        return view('products.create');
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request): RedirectResponse
    {
        $request->validate([
            'name'        => 'required',
            'description' => 'required',
            'price'       => 'required|numeric',
        ]);

        Product::create($request->all());

        return redirect()->route('products.index')
                         ->with('success', 'Product created successfully.');
    }

    /**
     * Display the specified resource.
     */
    public function show(Product $product): View
    {
        return view('products.show', compact('product'));
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(Product $product): View
    {
        return view('products.edit', compact('product'));
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, Product $product): RedirectResponse
    {
        $request->validate([
            'name'        => 'required',
            'description' => 'required',
            'price'       => 'required|numeric',
        ]);

        $product->update($request->all());

        return redirect()->route('products.index')
                         ->with('success', 'Product updated successfully.');
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(Product $product): RedirectResponse
    {
        $product->delete();

        return redirect()->route('products.index')
                         ->with('success', 'Product deleted successfully.');
    }
}

Step 5: Define Resource Routes

At this point, we have a model, migration, and controller, but Laravel still does not know which URLs should point to which controller methods. This is handled by routes.

Open the following file: routes/web.php

By default, it contains a basic route. We will now add a resource route for products.

Update the file like this:

use App\Http\Controllers\ProductController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return redirect()->route('products.index');
});

Route::resource('products', ProductController::class);

What this does:

  • Route::resource automatically creates all CRUD routes for us.
  • Laravel maps URLs like /products, /products/create, /products/{id}/edit to the correct controller methods.
  • The root URL / now redirects to the products list.

You do not need to manually define each route. Laravel handles it.

Step 6: Create the Views (Blade Templates)

Now we need something to display in the browser. Laravel uses Blade templates for views.

Create the following folder structure inside resources/views:

resources/views/products

Inside the products folder, create these files:

  • index.blade.php
  • create.blade.php
  • edit.blade.php
  • show.blade.php

We will also create a simple layout file to avoid repeating HTML.

1. Create a Base Layout

Inside resources/views, create a new file: layout.blade.php

Add the following code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Laravel CRUD</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div class="container mt-4">
    @yield('content')
</div>

</body>
</html>

This gives us a simple Bootstrap layout that all pages will reuse.

2. Product List View (Index)

Open: resources/views/products/index.blade.php

Add the following:

@extends('layout')

@section('content')

<h2 class="mb-3">Products</h2>

<a href="{{ route('products.create') }}" class="btn btn-primary mb-3">
    Add New Product
</a>

@if(session('success'))
    <div class="alert alert-success">
        {{ session('success') }}
    </div>
@endif

<table class="table table-bordered">
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Price</th>
        <th width="250">Actions</th>
    </tr>

    @foreach ($products as $product)
        <tr>
            <td>{{ $product->id }}</td>
            <td>{{ $product->name }}</td>
            <td>{{ $product->price }}</td>
            <td>
                <a class="btn btn-info btn-sm" href="{{ route('products.show', $product->id) }}">View</a>
                <a class="btn btn-warning btn-sm" href="{{ route('products.edit', $product->id) }}">Edit</a>

                <form action="{{ route('products.destroy', $product->id) }}" method="POST" style="display:inline;">
                    @csrf
                    @method('DELETE')
                    <button class="btn btn-danger btn-sm" type="submit">
                        Delete
                    </button>
                </form>
            </td>
        </tr>
    @endforeach
</table>

{{ $products->links() }}

@endsection

This page lists all products, shows success messages, and provides buttons for all CRUD actions.

3. Create Product Form

Open: resources/views/products/create.blade.php

Add this code:

@extends('layout')

@section('content')

<h2>Add New Product</h2>

<form action="{{ route('products.store') }}" method="POST">
    @csrf

    <div class="mb-3">
        <label>Name</label>
        <input type="text" name="name" class="form-control">
    </div>

    <div class="mb-3">
        <label>Description</label>
        <textarea name="description" class="form-control"></textarea>
    </div>

    <div class="mb-3">
        <label>Price</label>
        <input type="text" name="price" class="form-control">
    </div>

    <button type="submit" class="btn btn-success">
        Save Product
    </button>
</form>

@endsection

This form submits data directly to the store method of the controller.

4. Edit Product Form

Open: resources/views/products/edit.blade.php

Add the following:

@extends('layout')

@section('content')

<h2>Edit Product</h2>

<form action="{{ route('products.update', $product->id) }}" method="POST">
    @csrf
    @method('PUT')

    <div class="mb-3">
        <label>Name</label>
        <input type="text" name="name" value="{{ $product->name }}" class="form-control">
    </div>

    <div class="mb-3">
        <label>Description</label>
        <textarea name="description" class="form-control">{{ $product->description }}</textarea>
    </div>

    <div class="mb-3">
        <label>Price</label>
        <input type="text" name="price" value="{{ $product->price }}" class="form-control">
    </div>

    <button type="submit" class="btn btn-primary">
        Update Product
    </button>
</form>

@endsection

This page loads existing data and updates it using the update method.

5. Show Single Product

Open: resources/views/products/show.blade.php

Add this:

@extends('layout')

@section('content')

<h2>Product Details</h2>

<div class="card">
    <div class="card-body">
        <h4>{{ $product->name }}</h4>
        <p>{{ $product->description }}</p>
        <strong>Price:</strong> {{ $product->price }}
    </div>
</div>

<a href="{{ route('products.index') }}" class="btn btn-secondary mt-3">
    Back
</a>

@endsection

Step 7: Run and Test the Project Locally

Everything is now connected.

Make sure your local server is running:

php artisan serve

Open your browser and visit:

http://127.0.0.1:8000

You should now be able to:

  • See the products list page
  • Add a new product
  • View product details
  • Edit existing products
  • Delete products
  • See success messages after each action

And that is it. You have now completed a full Laravel 11 CRUD application using:

  • Migrations for database structure
  • Eloquent models for data interaction
  • Resource controllers for clean logic
  • Blade templates for UI
  • Laravel’s built-in development server for local testing

Here is the final output:

laravel crud operations

Deploying Your Laravel App to Production

Great job! You have a working CRUD application running on your laptop. But software isn’t finished until it’s online. In this section, we will take your local code and deploy it to a live, production-grade server using Cloudways.

We will use a professional workflow: Git Version Control. This allows you to push updates to GitHub, and then have your server automatically pull those changes.

Prerequisites for Deployment

Before proceeding, ensure you have the following:

1. Initialize Git Locally

Right now, your code just lives in a folder on your computer. We need to tell Git to start tracking it.

Open your terminal (Command Prompt or Terminal) inside your project folder (product-app) and run the following commands one by one:

# 1. Initialize a new Git repository
git init

Note: If you get an error saying ‘git is not recognized’, verify that you installed Git (from the prerequisites above) and restart your terminal.

# 2. Add all your files to the "staging area"
git add .

# 3. Save these files with a message (Commit)
git commit -m "Initial CRUD application complete"

# 4. Rename the default branch to 'main' (Standard practice)
git branch -M main

Your code is now “locked in” locally. Next, we need to send it to the cloud.

2. Push Code to GitHub

We need a bridge between your laptop and your server. GitHub is that bridge.

  • Log in to your GitHub account.
  • Look for the + icon in the top-right corner and select New repository.

create new github repository

  • Repository Name: Enter laravel-crud-app.
  • Visibility: Choose Public (easiest for this tutorial) or Private.
  • Click the green Create repository button.

create repository

GitHub will now give you a unique URL for your project.

github repo URL

Copy the commands under the section titled “…or push an existing repository from the command line”. They will look like this:

git remote add origin https://github.com/abdulrehman293/laravel-crud-app.git
git branch -M main
git push -u origin main

Paste those commands into your terminal and hit Enter. If asked, sign in to GitHub.

sign into git using terminal

Success Check: Refresh your GitHub page. You should see all your Laravel files (app, database, resources, etc.) listed there.

Laravel files (app, database, resources, etc.) listed

3. Set Up the Cloudways Server

Now we need a place to host the app.

  • Log in to the Cloudways Platform.
  • Create a new server. I already have one, so I’ll just create a new application.

Add Application in cloudways

  • Application: Select Laravel.
  • Name Your App: ProductApp.

create laravel app on cloudways

Wait a few minutes for the server to spin up. Cloudways is automatically installing PHP 8.2, Nginx, MySQL, and everything else we need.

4. Connect Cloudways to GitHub

This is the magic part. We need to give Cloudways permission to download your code from GitHub.

  • Click on Applications in the top menu and select your ProductApp.
  • In the left sidebar, under “Deployment”, click on Deployment via Git.

deployment via git option in cloudways

  • Click the Generate SSH Keys button.

generate ssh keys

  • Click View SSH Key and copy the entire text string.

view ssh keys

Now, hand that key over to GitHub:

  • Go back to your GitHub repository page.
  • Click Settings (top tab) → Deploy Keys (left sidebar).

deploy keys in github

  • Click Add deploy key.
  • Title: “Cloudways Server”.
  • Key: Paste the key you copied from Cloudways.
  • Click Add key.

add deploy keys from cloudways to github

5. Deploy the Code

The handshake is complete. Now let’s pull the code.

Important: Cloudways works best with the SSH Link, not the HTTPS link.

  1. Go back to your GitHub repository page.
  2. Click the green Code button.
  3. Select the SSH tab (not HTTPS).
  4. Copy the URL that starts with git@ (e.g., [email protected]:username/repo.git).

Note: If GitHub says “You don’t have any public SSH keys”, ignore it. We added the key to the Repository settings, not your personal account, so it will still work.

Back on Cloudways:

  • Paste the SSH URL into the GIT Remote Address field.
  • Click Authenticate. The field should turn green.
  • In the Branch dropdown that appears, select main.
  • The Start Deployment button will now turn blue. Click it!

add git remote access in cloudways

Cloudways will now download your code from GitHub and place it on the server. This usually takes 10–20 seconds. Once finished, you will see a “Pull” button where there was Start Deployment button.

6. Final Setup: The Database

Your code is live, but if you visit your website URL right now, you might see an error.

error when visiting cloudways laravel app after git deployment

Why?

Because of two things:

  1. Our server dependencies (like Laravel libraries) aren’t installed yet.
  2. Our application doesn’t know the production database password yet.

We will fix both right now in the terminal.

Part A: Get Your Application Folder Name

Since a Cloudways server can host multiple apps, we need to know exactly which folder your app lives in.

  • Go to your Application Dashboard on Cloudways.
  • Click on Access Details in the sidebar.
  • Look for the field labeled DB Name (it will be a random name like hzyrjqzuhc).
  • Copy that name to your clipboard.

copy database name from access details in cloudways dashboard

Part B: Launch the Terminal

  • Click on Servers in the top menu bar.
  • Select your server.
  • Ensure you are on the Master Credentials tab.
  • Click the Launch SSH Terminal button.

cloudways master credentials for server

Part C: Navigate to Your App

A terminal window will open. You need to enter your specific application folder using the name you copied in Part A.

Type the following command, but replace [YOUR_DB_NAME] with the text you just copied:

cd applications/[YOUR_DB_NAME]/public_html

log into ssh terminal on cloudways server and access your app folder

Part D: Install Laravel Dependencies

Since we don’t upload the “vendor” folder to GitHub, we need to install Laravel’s core libraries on the server manually. Run this command:

composer install

(This will take about a minute as it downloads the necessary packages.)

Part E: Update Database Credentials

By default, your app is still trying to connect to “localhost” with “root“. We need to give it the Cloudways database credentials.

1. In the terminal, run this command to open your configuration file:

nano .env

2. Use the Down Arrow key to scroll until you find the DB_ section.

3. Update the DB_DATABASE, DB_USERNAME, and DB_PASSWORD to match the credentials found in your Cloudways Access Details tab.

DB_DATABASE=your_cloudways_db_name 
DB_USERNAME=your_cloudways_username 
DB_PASSWORD=your_cloudways_password

4. Press Ctrl + X, then Y, then Enter to save and exit.

Part F: Run the Migration

Now that the database is connected, we will create the tables. We use the :fresh command to ensure we start with a clean slate and avoid any conflicts with pre-existing default tables.

php artisan migrate:fresh --force

You should see a list of tables being created (Creating: products, etc.) ending with green “DONE” messages.

running migrations in cloudways ssh terminal

7. Test Your Live App

That’s it! The hard work is done.

Go back to the Application > Access Details tab and click your Application URL. Add /products to the end of the link.

You should now see your Laravel 11 CRUD application running live on the production server. Like this:

laravel crud app deployed on live cloudways server

And here it is in action:

laravel-crud-on-cloudways-server

And that is it. In this guide, you:

  • Set up a local development environment.
  • Built a Laravel 11 application with Models, Views, and Controllers.
  • Implemented full CRUD functionality (Create, Read, Update, Delete).
  • Versioned your code using Git.
  • Deployed your application to a live Cloudways server.

This is just the beginning. From here, you can add user authentication, image uploads, or API integration. Whatever you build, Cloudways is ready to host it. Start your free trial today.

Laravel CRUD Optimization Tips

Optimizing the performance of a Laravel CRUD application is crucial for ensuring that your web application runs smoothly and efficiently.

Here are some tips to help you improve the performance of your Laravel CRUD application:

  • Caching: Use Laravel’s built-in caching system to store frequently accessed data. You can use tools like Redis or Memcached to cache query results, views, and configurations, reducing load on your database.
  • Eager Loading: The N+1 query problem is a common performance killer. When retrieving data with relationships, use the with() method to load related data upfront.
$products = Product::with('category')->get();
  • Database Indexing: Properly index your database tables to speed up search queries. You can add indexes directly in your migration files.
Schema::table('products', function ($table) {
    $table->index('name'); // Speeds up searching by product name
});
  • Database Transactions: Wrap multiple database operations in a transaction. This ensures data consistency (if one fails, they all fail) and can improve write performance.
DB::transaction(function () {
    // Create Product
    // Create Inventory Record
    // Deduct Stock
});
  • Query Optimization: Avoid using select * on large tables. Instead, select only the columns you actually need. Also, always use Pagination (as we did in the Product Controller) to avoid crashing the browser with thousands of records.
  • Use Queues: Offload time-consuming tasks like sending email notifications or processing image uploads to background queues. This keeps your user interface snappy.

Move From Localhost to Live in Minutes

You’ve built the app—now launch it without the stress. Connect your GitHub repo to Cloudways and deploy your code to a production-grade server automatically.

Summary

In this guide, we built a complete Laravel CRUD application from scratch and launched it to the world.

We started by setting up a local environment and writing the backend logic to Create, Read, Update, and Delete data. Then, we moved to the frontend, designing a clean interface with Blade templates and Tailwind CSS.

Finally, we tackled the most important part: pushing the code to GitHub and deploying it to a live production server on Cloudways.

Get the Code: The complete source code for this project is available on GitHub. You can view it, download it, or clone it here: Laravel 11 CRUD App Repository.

You now have a working application and a professional deployment workflow. From here, you can easily expand this project—perhaps by adding User Authentication—knowing your infrastructure is ready to handle it.

Q. How to install a CRUD generator for Laravel?

A. If you want to skip writing manual code, you can use a package like InfyOm Laravel Generator. Run this command in your terminal:

composer require infyomlabs/laravel-generator

However, for learning purposes, we recommend building your first CRUD app from scratch as shown in this guide.

Q. How to create CRUD in Laravel 11?

A. To create the necessary files for a CRUD app (e.g., for Products), use this single Artisan shortcut command:

php artisan make:model Product -mcr

This creates the Model, Migration, and a Controller pre-filled with CRUD methods (index, create, store, etc.).

Q. How do you perform CRUD operations in Laravel?

A. CRUD corresponds to four Eloquent methods:

  • Create: Product::create($data);
  • Read: Product::all(); or Product::findOrFail($id);
  • Update: $product->update($data);
  • Delete: $product->delete();

Q. How to perform a delete operation in Laravel?

A. To delete a record safely, find it first and then call delete. Here is the standard controller method:

public function destroy($id) {
    $product = Product::findOrFail($id);
    $product->delete();
    return redirect()->route('products.index')->with('success', 'Product deleted successfully.');
}

Q. How do I deploy my Laravel CRUD app?

A. Deployment involves three main steps:

  1. Push your local code to a GitHub repository.
  2. Connect your cloud server (like Cloudways) to that repository to pull the code.
  3. Run composer install and php artisan migrate --force on the server to set up the live database.

Q. How can you customize Laravel CRUD?

A. Once the basics are working, you can customize your CRUD app by adding Form Validation (using Request classes), Pagination (using ->paginate(10)), or adding Search Filters to your index method.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Abdul Rehman

Abdul is a tech-savvy, coffee-fueled, and creatively driven marketer who loves keeping up with the latest software updates and tech gadgets. He's also a skilled technical writer who can explain complex concepts simply for a broad audience. Abdul enjoys sharing his knowledge of the Cloud industry through user manuals, documentation, and blog posts.

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour