Home Laravel 9 Laravel 11 School Management System

Laravel 11 School Management System

6 min read
0
0
23

In this tutorial, we will teach you how to create a simple school management system using Laravel 11. This lesson primarily covers student registration and student records management.

Installing Laravel 11

Create the new project which name is schoolmanagment-app.type by following command to create the Laravel project.

composer create-project laravel/laravel schoolmanagement-app

After typing the command, wait until the project installation completes. Once it’s finished, let’s proceed with the database setup.

Change .env File

By Default Database Connection in Laravel 11 as Sqllite

By Default Connection

DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=

To change the MySQL connection, follow these steps:

  1. Set the connection type to MySQL.
  2. Enter the user credentials, including the database username and password.
  3. Specify the database name.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=dbschoolmanagement
DB_USERNAME=root
DB_PASSWORD=

Run the Project

Run the Application using following command

php artisan serve

Create Migrations

In Laravel create the table called as Migration

Run the command to create the Migration

php artisan make:migration create_students_table

After that you can check the inside  database folder migrations  create_students_table file has been created
successfully.

Select and open the students table. add the following table fields empname,dob,phone

public function up(): void
   {
       Schema::create('students', function (Blueprint $table) {
           $table->id();
           $table->string('student_name');
           $table->date('dob');
           $table->string('address')->nullable();
           $table->string('status')->default('active');
           $table->timestamps();
       });

   }

After modified the columns names  then run the migrate command to create the tables in the databases.before the run the
command please save project then run it.

php artisan migrate

Create Controller

Create Controller
php artisan make:controller StudentController

After creating the controller, paste the following code snippet

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Student;
use App\Models\StuRecord;


class StudentController extends Controller
{

    protected $student;
    protected $student_record;

    public function __construct(){

        $this->student = new Student();
        $this->student_record = new StudentRecord();

    }

    public function index(){

        $response['students'] = $this->student->all();
        return view('pages.student.index')->with($response);

    }

    public function save(Request $request){

        //dd($request->all());

        $this->student->create($request->all());
        return redirect()->back();

    }


    public function delete($student_id){

        $student = $this->student->find($student_id);
        $student->delete();
        return redirect()->back();

    }


    public function edit($student_id){

        $response['student'] = $this->student->find($student_id);
        return view('pages.student.edit')->with($response);
    }



    public function update(Request $request, $student_id){

        $student = $this->student->find($student_id);

        $student->update(array_merge($student->toArray(), $request->toArray()));
        return redirect('student');

    }


    public function vewRecords($student_id){

        $response['student'] = $this->student->find($student_id);
        $response['studentrecords'] = $this->stu_record->where('student_id', $student_id)->get();

        return view('pages.student.manage')->with($response);
    }

    public function saveRecord(Request $request){

        $this->student_record->create($request->all());
        return redirect()->back();
    }


}

After create the controller need to create the model.

Create Model

Model is used to get the data from the database.

Create the Model name which is Student

php artisan make:model Employee

After Model is Created the look like this. Code inside Model Class (app\Models\)

Change it as like this

Add the Namespace above

 

protected $fillable = [
       'student_name',
       'dob',
       'address',
       'status'
   ];

Create Views

inside the views folder

create layouts folder.inside the folder create a file app.blade.php. inside the file paste this following codes.

app.blade.php

 

 

    Load More Related Articles
    Load More By admin
    Load More In Laravel 9

    Leave a Reply

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

    Check Also

    How to Make a Admin Panel Using React MUI

    I have design the Admin Basic templete using React MUI Design Admin Dashboard and Login.He…