create a student management system using laravel-12

Complete scaffold to create a Student Management System using Laravel 12. I give you commands, migrations, model, controller, routes, Blade views, validation, and seeder/factory so you can copy-paste and get a working CRUD app with authentication (Breeze).

Quick prerequisites

(Official Laravel 12 install notes and starter-kits referenced below.) Laravel Doc

1) Create new Laravel 12 project

Run (either laravel new or composer):

 bash

# with Laravel installer (recommended)
composer global require laravel/installer
laravel new student-management
# or with composer
composer create-project laravel/laravel student-management
cd student-management

(Installation/creating a project: Laravel docs.)
Laravel

2) Install an auth starter (Breeze) so app has login/register

 bash

composer require laravel/breeze --dev
php artisan breeze:install blade
npm install
npm run dev
php artisan migrate

(You can also choose other kits; Breeze is simple and common.)
Laravel Daily

3) Create Student model + migration + factory + resource controller

 bash

php artisan make:model Student -m -f -c --resource

This creates:

4) Migration: create_students_table

Replace migration contents with (example fields: name, email, roll, course, year, status):

 bash

// database/migrations/2025_xx_xx_create_students_table.php
public function up()
{
    Schema::create('students', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->string('roll')->unique();
        $table->string('course')->nullable();
        $table->unsignedSmallInteger('year')->nullable();
        $table->boolean('status')->default(true); // active/inactive
        $table->timestamps();
    });
}

Run:

 bash

php artisan migrate

5) Student model

 bash

// app/Models/Student.php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
class Student extends Model
{
    use HasFactory;
    protected $fillable = [
        'name',
        'email',
        'roll',
        'course',
        'year',
        'status',
    ];
}

6) StudentController (resource) — full CRUD + simple search & pagination

Replace controller with:

 bash

// app/Http/Controllers/StudentController.php
namespace AppHttpControllers;
use AppModelsStudent;
use IlluminateHttpRequest;
class StudentController extends Controller
{
    public function __construct()
    {
        // require auth for all student routes
        $this->middleware('auth');
    }
    public function index(Request $request)
    {
        $q = $request->query('q');
        $students = Student::when($q, fn($query) => $query->where('name', 'like', "%{$q}%")
                                                           ->orWhere('email', 'like', "%{$q}%")
                                                           ->orWhere('roll', 'like', "%{$q}%"))
                           ->orderBy('id', 'desc')
                           ->paginate(10)
                           ->withQueryString();
        return view('students.index', compact('students','q'));
    }
    public function create()
    {
        return view('students.create');
    }
    public function store(Request $request)
    {
        $data = $request->validate([
            'name'  => 'required|string|max:255',
            'email' => 'required|email|unique:students,email',
            'roll'  => 'required|string|unique:students,roll',
            'course'=> 'nullable|string|max:255',
            'year'  => 'nullable|integer|min:1900|max:2100',
            'status'=> 'nullable|boolean',
        ]);
        $data['status'] = $request->has('status') ? (bool)$request->status : true;
        Student::create($data);
        return redirect()->route('students.index')->with('success', 'Student created.');
    }
    public function show(Student $student)
    {
        return view('students.show', compact('student'));
    }
    public function edit(Student $student)
    {
        return view('students.edit', compact('student'));
    }
    public function update(Request $request, Student $student)
    {
        $data = $request->validate([
            'name'  => 'required|string|max:255',
            'email' => 'required|email|unique:students,email,'.$student->id,
            'roll'  => 'required|string|unique:students,roll,'.$student->id,
            'course'=> 'nullable|string|max:255',
            'year'  => 'nullable|integer|min:1900|max:2100',
            'status'=> 'nullable|boolean',
        ]);
        $data['status'] = $request->has('status') ? (bool)$request->status : false;
        $student->update($data);
        return redirect()->route('students.index')->with('success','Student updated.');
    }
    public function destroy(Student $student)
    {
        $student->delete();
        return redirect()->route('students.index')->with('success','Student deleted.');
    }
}

7) Routes (routes/web.php)

Add resource routes and a home redirect:

 bash

use AppHttpControllersStudentController;
Route::get('/', function () {
    return redirect()->route('students.index');
});
Route::middleware(['auth'])->group(function() {
    Route::resource('students', StudentController::class);
});
require __DIR__.'/auth.php'; // Breeze auth routes

8) Blade views (minimal UI with Tailwind — Breeze already installs Tailwind)

Create these view files under resources/views/students/:

 bash

@extends('layouts.app')
@section('content')
<div>
    <div>
        <form action="{{ route('students.index') }}" method="GET">
            <input name="q" value="{{ $q }}" placeholder="Search name, email, roll" />
            <button>Search</button>
        </form>
        <a href="{{ route('students.create') }}">Add Student</a>
    </div>
    @if(session('success'))
        <div>{{ session('success') }}</div>
    @endif
    <table>
        <thead>
            <tr>
                <th>#</th>
                <th>Name</th>
                <th>Email</th>
                <th>Roll</th>
                <th>Course</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            @foreach($students as $student)
            <tr>
                <td>{{ $student->id }}</td>
                <td>{{ $student->name }}</td>
                <td>{{ $student->email }}</td>
                <td>{{ $student->roll }}</td>
                <td>{{ $student->course }}</td>
                <td>
                    <a href="{{ route('students.show', $student) }}">View</a>
                    <a href="{{ route('students.edit', $student) }}">Edit</a>
                    <form action="{{ route('students.destroy', $student) }}" method="POST" onsubmit="return confirm('Delete?')">
                        @csrf @method('DELETE')
                        <button>Delete</button>
                    </form>
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
    <div>
        {{ $students->links() }}
    </div>
</div>
@endsection

create.blade.php / edit.blade.php / show.blade.php

Use straightforward forms and fields matching validation rules. (If you want, I can paste full create/edit/show files too.)

9) Factory & Seeder (optional — for test data)

Example factory:

 bash

// database/factories/StudentFactory.php
public function definition()
{
    return [
        'name' => $this->faker->name(),
        'email' => $this->faker->unique()->safeEmail(),
        'roll' => strtoupper($this->faker->bothify('RLL####')),
        'course' => $this->faker->randomElement(['CSE','EEE','BBA','ENG']),
        'year' => $this->faker->numberBetween(2018, 2025),
        'status' => $this->faker->boolean(90),
    ];
}

Seeder:

 bash

// database/seeders/DatabaseSeeder.php
public function run()
{
    AppModelsStudent::factory(50)->create();
}

Run seeder:

 bash

php artisan db:seed

10) Run the app

 bash

# dev server
php artisan serve

Final Thought

References (official docs)

Leave a Reply

Your email address will not be published. Required fields are marked *