Step-by-Step Guide to Creating Your First Laravel CRUD App

Prashant DasnurPrashant Dasnur
2 min read

Laravel is an elegant framework that simplifies backend development. This tutorial guides you through creating your first CRUD (Create, Read, Update, Delete) application โ€” a Blog Post Management System. Perfect for beginners and developers looking to refresh their Laravel knowledge.

๐Ÿšง Introduction

๐Ÿ”น Why Laravel?

  • Developer-friendly syntax

  • Built-in tools (Artisan, Eloquent ORM, Blade templating)

  • Rapid CRUD development

๐Ÿ”น Project Objective:

Create a Blog Post Manager with full CRUD functionality.

๐Ÿ”น Tech Stack:

  • Laravel (v10 or latest)

  • Composer

  • PHP (โ‰ฅ8.1)

  • XAMPP / Laravel Sail / Valet

๐Ÿ”ง Step 1: Configure Your Laravel Environment

โš™๏ธ Install Laravel

composer create-project laravel/laravel blog-crud
cd blog-crud

Or use Laravel Sail for Docker-powered setup:

./vendor/bin/sail up

๐ŸŒ Set Up Environment

  • Edit .env file for DB settings:
DB_DATABASE=blog_db
DB_USERNAME=root
DB_PASSWORD=
  • Create database manually or via migration

  • Run migrations:

php artisan migrate

๐Ÿงฑ Step 2: Generate Model, Migration & Controller

Run one-liner to generate all three:

php artisan make:model Post -mcr

๐Ÿ”ง In database/migrations/xxxx_create_posts_table.php:

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

Run migration:

php artisan migrate

๐Ÿ›ฃ๏ธ Step 3: Configure Routes

In routes/web.php, register a resource route:

use App\\Http\\Controllers\\PostController;

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

This creates all 7 RESTful routes automatically (index, create, store, etc.)


๐Ÿ–ผ๏ธ Step 4: Build Blade Templates

๐Ÿ”น Create a resources/views/posts directory

๐Ÿ”น Add files: index.blade.php, create.blade.php, edit.blade.php, show.blade.php

Each form should use:

@csrf
@method('PUT') {{-- only for edit --}}

Use route helpers like:

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

๐Ÿง  Step 5: Add Controller Logic

Inside PostController.php:

public function index() {
    $posts = Post::all();
    return view('posts.index', compact('posts'));
}

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

public function store(Request $request) {
    Post::create($request->all());
    return redirect()->route('posts.index');
}

public function edit(Post $post) {
    return view('posts.edit', compact('post'));
}

public function update(Request $request, Post $post) {
    $post->update($request->all());
    return redirect()->route('posts.index');
}

public function destroy(Post $post) {
    $post->delete();
    return redirect()->route('posts.index');
}

๐Ÿ‘‰ Add fillable fields in Post.php:

protected $fillable = ['title', 'body'];

โœ… Step 6: Test Your Application

php artisan serve

Visit: http://127.0.0.1:8000/posts

Perform the full CRUD cycle:

  • ๐Ÿ“ Create

  • ๐Ÿ“– Read

  • โœ๏ธ Update

  • โŒ Delete

You've now created a fully functional CRUD app with Laravel!

Next steps for scaling this project:

  • โœ… Add form validation ($request->validate())

  • โœ… Implement Laravel UI or Breeze for authentication

  • โœ… Introduce Eloquent relationships (e.g., User โ†’ Posts)

  • โœ… Deploy via Laravel Forge or Vercel (with APIs)

๐Ÿ“ Supplementary Resources

0
Subscribe to my newsletter

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

Written by

Prashant Dasnur
Prashant Dasnur

Iโ€™m an MCA graduate with a passion for building modern web applications.Currently exploring Laravel and React, and sharing my learning journey through blogs and projects.I enjoy solving real-world problems with clean code and creative thinking.Always learning, always building. ๐Ÿ’ป๐Ÿš€