Laravel 12 Crud Application with Live Example

Laravel 12 is a newly release laravel framework. This laravel framework provides an easiest way to make software application as well as crud. In this article we will use bootstrap and laravel 12 framework to make simple laravel 12 crud application. For demonstration we will use course implementation. Here I have also shared a github repo link at bottom for reference. 


Steps to Create Laravel 12 CRUD Application

  1. Install Fresh Laravel 12 Project
  2. Create Necessary Model 
  3. Create Necessary Controller
  4. Edit Migration File
  5. Define Routes for Handline Requests
  6. Add Blade Files 

1 - Install Fresh Laravel 12 Project

For this article we will create a fresh new empty laravel 12 project. Here we are going to implement crud functionality. Here below is the command for making fresh laravel 12 project

composer create-project --prefer-dist laravel/laravel laravel12-crud 12.*
cd laravel12-crud

2 - Create Necessary Model

Here we will create course model and after that along with course model migration, factory will be created. Here is the below command for making course model. This course will be created inside App/Models/Course.php

php artisan make:model Course -fm

3 - Create Necessary Controller

We will have to handle requests coming from frontend. That's why we will create a controller that will be used for processing the requests. 

php artisan make:controller CourseController -r

Here is the controller implementation 

namespace App\Http\Controllers;

use App\Models\Course;
use Illuminate\Http\Request;

class CourseController extends Controller
{
    public function index()
    {
        $courses = Course::all();
        return view('courses.index', compact('courses'));
    }

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

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

        Course::create($request->all());
        return redirect()->route('courses.index')->with('success', 'Course created successfully.');
    }

    public function show(Course $course)
    {
        return view('courses.show', compact('course'));
    }

    public function edit(Course $course)
    {
        return view('courses.edit', compact('course'));
    }

    public function update(Request $request, Course $course)
    {
        $request->validate([
            'title' => 'required',
            'price' => 'required|numeric',
        ]);

        $course->update($request->all());
        return redirect()->route('courses.index')->with('success', 'Course updated successfully.');
    }

    public function destroy(Course $course)
    {
        $course->delete();
        return redirect()->route('courses.index')->with('success', 'Course deleted successfully.');
    }
}

Read also: Laravel 11 sanctum api login registration

Read also: Make sitemap using laravel

Read also: Laravel 12 pdf file create in dompdf

4 - Edit Migration File

Now we will edit migration file created for course crud functionality . Here is the code for migration

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
	//database/migrations/2025_03_06_133654_create_courses_table.php
	
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('courses', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->text('description')->nullable();
            $table->decimal('price', 8, 2);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('courses');
    }
};

5 - Define Routes for Handline Requests

We need to define routes for handling requests. We are using route resource here  to make it simple and fancy

//routes/web.php

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

Route::resource('courses', CourseController::class);

6 - Add Blade Files 

We need to create blade files for our frontend. We are using bootstrap for quick design. We can also use tailwind, material css or other frontend library as well.


resources/views/layouts/app.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Course CRUD App</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- Header -->
<nav class="navbar navbar-expand-lg navbar-dark bg-success">
    <div class="container">
        <a class="navbar-brand" href="{{ route('courses.index') }}">Course App</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="{{ route('courses.index') }}">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="{{ route('courses.create') }}">Add Course</a>
                </li>
            </ul>
        </div>
    </div>
</nav>
<div class="container mt-4">
    <div class="card">
        <div class="card-body">
            @yield('content')
        </div>
    </div>
</div>
</body>
</html>


resources/views/courses/create.blade.php

@extends('layouts.app')

@section('content')
        <h2>Add Course</h2>
        <form action="{{ route('courses.store') }}" method="POST">
            @csrf
            <div class="mb-3">
                <label class="form-label">Title</label>
                <input type="text" name="title" class="form-control" required>
            </div>
            <div class="mb-3">
                <label class="form-label">Description</label>
                <textarea name="description" class="form-control"></textarea>
            </div>
            <div class="mb-3">
                <label class="form-label">Price</label>
                <input type="number" name="price" class="form-control" step="0.01" required>
            </div>
            <button type="submit" class="btn btn-success">Save</button>
        </form>
@endsection


resources/views/courses/edit.blade.php

@extends('layouts.app')

@section('content')
    <h2>Edit Course</h2>
    <form action="{{ route('courses.update', $course->id) }}" method="POST">
        @csrf
        @method('PUT')
        <div class="mb-3">
            <label class="form-label">Title</label>
            <input type="text" name="title" class="form-control" value="{{ $course->title }}" required>
        </div>
        <div class="mb-3">
            <label class="form-label">Description</label>
            <textarea name="description" class="form-control">{{ $course->description }}</textarea>
        </div>
        <div class="mb-3">
            <label class="form-label">Price</label>
            <input type="number" name="price" class="form-control" value="{{ $course->price }}" step="0.01" required>
        </div>
        <button type="submit" class="btn btn-success">Update</button>
    </form>
@endsection

resources/views/courses/index.blade.php
@extends('layouts.app')

@section('content')
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h2>Course List</h2>
        <a href="{{ route('courses.create') }}" class="btn btn-primary">Add Course</a>
    </div>

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

        <table class="table table-bordered">
            <thead>
            <tr>
                <th class="text-center">#</th>
                <th class="text-center">Title</th>
                <th class="text-center">Price</th>
                <th class="text-center">Actions</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($courses as $course)
                <tr>
                    <td>{{ $loop->iteration }}</td>
                    <td>{{ $course->title }}</td>
                    <td class="text-center">${{ $course->price }}</td>
                    <td class="text-center">
                        <a href="{{ route('courses.show', $course->id) }}" class="btn btn-info btn-sm">View</a>
                        <a href="{{ route('courses.edit', $course->id) }}" class="btn btn-warning btn-sm">Edit</a>
                        <form action="{{ route('courses.destroy', $course->id) }}" method="POST" class="d-inline">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn btn-danger btn-sm"
                                    onclick="return confirm('Are you sure?')">Delete
                            </button>
                        </form>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
@endsection

resources/views/courses/show.blade.php
@extends('layouts.app')

@section('content')
        <h2>{{ $course->title }}</h2>
        <p>{{ $course->description }}</p>
        <p><strong>Price:</strong> ${{ $course->price }}</p>
        <a href="{{ route('courses.index') }}" class="btn btn-primary">Back</a>
@endsection

Read also: Laravel 11 intervention image upload with resize example

Read also: Laravel 11 file upload in storage directory


After running and visiting url 127.0.0.1:8000/courses , final output will be like below. Here is the screenshot. 

laravel 12 crud application - programmingmindset.com

Github repo link

Tags: