Building Your First CRUD App in Laravel: A Step-by-Step Guide for Beginners

Rohit DhimanRohit Dhiman
3 min read

If you're just starting your journey with Laravel, one of the best beginner projects you can build is a CRUD app. It covers all the fundamental concepts you'll use in real-world Laravel development: routing, controllers, database operations, views, validation, and more.

In this tutorial, Iโ€™ll walk you through how to build a simple Post Management System that lets you Create, Read, Update, and Delete posts.

Letโ€™s dive in ๐Ÿ‘‡


โœ… What Youโ€™ll Learn

  • How Laravel routes and controllers work

  • How to connect and use a database with Laravel

  • How to use resource controllers

  • How to build forms using Blade templates

  • How to validate and persist form data


๐Ÿ”ง Tools & Prerequisites

Before we begin, make sure you have:

  • PHP 8.x installed

  • Composer installed

  • Laravel CLI installed (composer global require laravel/installer)

  • A database (MySQL or SQLite)

  • VS Code or your favorite editor


๐Ÿ“ Step 1: Create a New Laravel Project

laravel new crud-app
cd crud-app

Or using Composer:

composer create-project laravel/laravel crud-app

โš™๏ธ Step 2: Configure Your Database

Open the .env file and set up your MySQL or SQLite credentials:

DB_DATABASE=crud_app
DB_USERNAME=root
DB_PASSWORD=secret

Then run:

php artisan migrate

โœจ Step 3: Create a Model, Controller, and Migration

Weโ€™ll use Artisan to generate everything in one go:

php artisan make:model Post -mcr

This creates:

  • A Post model

  • A migration file

  • A resource controller (PostController)


๐Ÿงฑ Step 4: Define the Posts Table

Open the migration file in database/migrations/..._create_posts_table.php and add:

$table->string('title');
$table->text('content');

Run the migration:

php artisan migrate

๐Ÿ—บ๏ธ Step 5: Set Up Routes

In routes/web.php, register resourceful routes:

use App\Http\Controllers\PostController;

Route::resource('posts', PostController::class);

This creates all 7 routes automatically:

  • index

  • create

  • store

  • show

  • edit

  • update

  • destroy


๐Ÿง  Step 6: Build Out the Controller Logic

Inside PostController.php, add logic to handle CRUD:

public function index()
{
    $posts = Post::latest()->get();
    return view('posts.index', compact('posts'));
}

public function create()
{
    return view('posts.create');
}

public function store(Request $request)
{
    $data = $request->validate([
        'title' => 'required|max:255',
        'content' => 'required',
    ]);

    Post::create($data);
    return redirect()->route('posts.index')->with('success', 'Post created successfully!');
}

Repeat similar logic for edit, update, and destroy.


๐ŸŽจ Step 7: Create Blade Views

In resources/views/posts/, create these files:

  • index.blade.php โ†’ list all posts

  • create.blade.php โ†’ form to create

  • edit.blade.php โ†’ form to edit

Example for index.blade.php:

@foreach ($posts as $post)
    <h2>{{ $post->title }}</h2>
    <p>{{ $post->content }}</p>
    <a href="{{ route('posts.edit', $post) }}">Edit</a>
    <form action="{{ route('posts.destroy', $post) }}" method="POST">
        @csrf @method('DELETE')
        <button>Delete</button>
    </form>
@endforeach

๐ŸŒŸ Final Touch: Validation + Flash Messages

Use Laravel's built-in validation and flash messaging:

return redirect()->route('posts.index')->with('success', 'Post updated!');

And display the message in your Blade:

@if(session('success'))
    <p>{{ session('success') }}</p>
@endif

๐Ÿงฉ Whatโ€™s Next?

You just built your first full-stack Laravel CRUD app! ๐ŸŽ‰
Here are some challenges to take it further:

  • Add Laravel Breeze for authentication

  • Implement file uploads for featured images

  • Add search and pagination


๐Ÿ”— Bonus: GitHub Code

The full working source code is available here:
๐Ÿ‘‰ github.com/rohitdhiman91/laravel-crud-app


๐Ÿ™‹ Questions?

Feel free to leave a comment, connect with me on LinkedIn, or DM me on Twitter. Happy to help!


๐Ÿ Conclusion

Starting with a CRUD app is the best way to learn Laravel fundamentals. Once you get comfortable, you'll be ready to build more complex apps like blogs, dashboards, and eCommerce platforms.

Thanks for reading! If you found this helpful, consider sharing it ๐Ÿ™Œ


๐Ÿท๏ธ Tags

#Laravel #PHP #CRUD #WebDevelopment #Beginners #Fullstack #BackendDevelopment #LaravelTutorial

0
Subscribe to my newsletter

Read articles from Rohit Dhiman directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rohit Dhiman
Rohit Dhiman

Laravel developer with 10+ years experience building scalable backends, APIs, and full-stack systems. ๐Ÿ’ก Expect posts about: Laravel design patterns Stripe & Twilio integrations RESTful API tips Docker for Laravel devs AWS setups for backend scaling Letโ€™s learn & build together ๐Ÿš€