Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I worked on the migration database integrity constraints #301

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/Http/Controllers/MasterController.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<?php

namespace App\Http\Controllers;

use App\School;
use App\User;
use Illuminate\Http\Request;

class MasterController extends Controller
{

public function index() {
return view('masters.index');
$school_count = count(School::all());
$teachers = count(User::where('role', 'teacher')->get());
$students = count(User::where('role', 'student')->get());
$admins = count(User::where('role', 'admin')->get());
return view('masters.index',[
'school_count'=>$school_count,
'teachers_count'=>$teachers,
'students_count'=>$students,
'admins_count'=>$admins,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CreateSchoolsTable extends Migration
public function up()
{
Schema::create('schools', function (Blueprint $table) {
$table->increments('id');
$table->bigIncrements('id');
$table->string('name');
$table->string('established')->default('');
$table->text('about');
Expand Down
7 changes: 4 additions & 3 deletions database/migrations/2014_10_12_100000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ class CreateUsersTable extends Migration
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('role');
$table->tinyInteger('active');
$table->integer('school_id')->nullable();
$table->integer('code')->nullable();//school code Auto generated
$table->integer('student_code')->unique()->nullable();//Auto generated
$table->bigInteger('student_code')->unique()->nullable();//Auto generated
$table->string('gender')->default('');
$table->string('blood_group')->default('');
$table->string('nationality')->default('');
Expand All @@ -32,6 +31,8 @@ public function up()
$table->string('pic_path')->default('');
$table->tinyInteger('verified');
$table->integer('section_id')->unsigned()->nullable();
$table->bigInteger('school_id')->unsigned()->nullable();
$table->foreign('school_id')->references('id')->on('schools');
$table->rememberToken();
$table->timestamps();
});
Expand Down
8 changes: 5 additions & 3 deletions database/migrations/2017_12_21_065735_create_exams_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class CreateExamsTable extends Migration
public function up()
{
Schema::create('exams', function (Blueprint $table) {
$table->increments('id');
$table->bigIncrements('id');
$table->string('exam_name');
$table->tinyInteger('active');
$table->tinyInteger('notice_published');
$table->tinyInteger('result_published');
$table->integer('school_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ class CreateClassesTable extends Migration
public function up()
{
Schema::create('classes', function (Blueprint $table) {
$table->increments('id');
$table->bigIncrements('id');
$table->string('class_number');
$table->integer('school_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->string('group');
$table->foreign('school_id')->references('id')->on('schools');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ class CreateSectionsTable extends Migration
public function up()
{
Schema::create('sections', function (Blueprint $table) {
$table->increments('id');
$table->bigIncrements('id');
$table->string('section_number');
$table->integer('room_number');
$table->integer('class_id')->unsigned();
$table->integer('user_id')->unsigned()->default(0);
$table->bigInteger('class_id')->unsigned();
$table->bigInteger('user_id')->unsigned()->default(0);
$table->foreign('class_id')->references('id')->on('classes');
$table->foreign('user_id')->references('id')->on('users');

$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ public function up()
{
Schema::create('attendances', function (Blueprint $table) {
$table->increments('id');
$table->integer('student_id')->unsigned();
$table->integer('section_id')->unsigned();
$table->integer('exam_id')->unsigned();
$table->bigInteger('student_id')->unsigned();
$table->bigInteger('section_id')->unsigned();
$table->bigInteger('exam_id')->unsigned();
$table->tinyInteger('present')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
// $table->foreign('student_id')->references('student_code')->on('users');
$table->foreign('section_id')->references('id')->on('sections');
$table->foreign('exam_id')->references('id')->on('exams');
$table->foreign('user_id')->references('id')->on('users');

$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public function up()
$table->string('title');
$table->text('description');
$table->tinyInteger('active');
$table->integer('school_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class CreateNoticesTable extends Migration
public function up()
{
Schema::create('notices', function (Blueprint $table) {
$table->increments('id');
$table->bigIncrements('id');
$table->string('file_path');
$table->string('title');
$table->text('description');
$table->tinyInteger('active');
$table->integer('school_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
6 changes: 4 additions & 2 deletions database/migrations/2017_12_27_025512_create_events_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public function up()
$table->string('title');
$table->text('description');
$table->tinyInteger('active');
$table->integer('school_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public function up()
$table->increments('id');
$table->string('file_path');
$table->text('description');
$table->integer('teacher_id')->unsigned();
$table->integer('section_id')->unsigned();
$table->bigInteger('teacher_id')->unsigned();
$table->bigInteger('section_id')->unsigned();
$table->foreign('teacher_id')->references('id')->on('users');
$table->foreign('section_id')->references('id')->on('sections');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public function up()
$table->string('title');
$table->text('description');
$table->tinyInteger('active');
$table->integer('school_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CreateCoursesTable extends Migration
public function up()
{
Schema::create('courses', function (Blueprint $table) {
$table->increments('id');
$table->bigIncrements('id');
$table->string('course_name');
$table->integer('class_id')->unsigned();
$table->string('course_type');
Expand All @@ -35,11 +35,16 @@ public function up()
$table->integer('ct_fullmark');
$table->integer('final_fullmark');
$table->integer('practical_fullmark');
$table->integer('school_id')->unsigned();
$table->integer('exam_id')->unsigned();
$table->integer('teacher_id')->unsigned();
$table->integer('section_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->bigInteger('exam_id')->unsigned();
$table->bigInteger('teacher_id')->unsigned();
$table->bigInteger('section_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('exam_id')->references('id')->on('exams');
$table->foreign('teacher_id')->references('id')->on('users');
$table->foreign('section_id')->references('id')->on('sections');

$table->timestamps();
});
}
Expand Down
13 changes: 9 additions & 4 deletions database/migrations/2017_12_27_025556_create_grades_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ public function up()
$table->float('written', 8, 2);
$table->float('mcq', 8, 2);
$table->float('practical', 8, 2);
$table->integer('exam_id')->unsigned();
$table->bigInteger('exam_id')->unsigned();
$table->integer('student_id')->unsigned();
$table->integer('teacher_id')->unsigned();
$table->integer('course_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('teacher_id')->unsigned();
$table->bigInteger('course_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
// $table->foreign('student_id')->references('student_code')->on('users');
$table->foreign('course_id')->references('id')->on('courses');
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('teacher_id')->references('id')->on('users');
$table->foreign('exam_id')->references('id')->on('exams');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public function up()
$table->tinyInteger('active');
$table->text('message');
$table->integer('student_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
// $table->foreign('student_id')->references('student_code')->on('users');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public function up()
Schema::create('feedbacks', function (Blueprint $table) {
$table->increments('id');
$table->text('description');
$table->integer('teacher_id')->unsigned();
$table->bigInteger('teacher_id')->unsigned();
$table->integer('student_id')->unsigned();
$table->foreign('teacher_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
11 changes: 7 additions & 4 deletions database/migrations/2017_12_27_025644_create_books_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CreateBooksTable extends Migration
public function up()
{
Schema::create('books', function (Blueprint $table) {
$table->increments('id');
$table->bigIncrements('id');
$table->string('book_code',50)->unique();
$table->string('title',250);
$table->string('author',100);
Expand All @@ -25,9 +25,12 @@ public function up()
$table->text('about');
$table->string('type',10);
$table->integer('price');
$table->integer('class_id')->unsigned();
$table->integer('school_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('class_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('class_id')->references('id')->on('classes');
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
7 changes: 5 additions & 2 deletions database/migrations/2017_12_27_025738_create_forms_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public function up()
$table->increments('id');
$table->string('name');
$table->string('file_path');
$table->integer('school_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');

$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ public function up()
$table->string('phone_number');
$table->string('email')->unique();
$table->text('message');
$table->integer('school_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
3 changes: 2 additions & 1 deletion database/migrations/2017_12_27_025806_create_faqs_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public function up()
$table->increments('id');
$table->string('question');
$table->text('answer');
$table->integer('user_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
6 changes: 4 additions & 2 deletions database/migrations/2018_02_06_161642_create_fees_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up()
Schema::create('fees', function (Blueprint $table) {
$table->increments('id');
$table->string('fee_name');// or Re-admisson
$table->integer('school_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
// $table->string('fine_fee');//penalty
// $table->string('exam_fee');
// $table->string('registration_fee');
Expand All @@ -28,7 +28,9 @@ public function up()
// $table->string('internet_fee');
// $table->string('farewell_fee');
// $table->string('other_fee');
$table->integer('user_id');
$table->bigInteger('user_id')->unsigned();
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public function up()
$table->float('point');
$table->integer('from_mark');
$table->integer('to_mark');
$table->integer('school_id');
$table->integer('user_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ public function up()
{
Schema::create('issued_books', function (Blueprint $table) {
$table->increments('id');
$table->integer('student_code');
$table->integer('book_id')->unsigned();
$table->bigInteger('student_code');
$table->bigInteger('book_id')->unsigned();
$table->integer('quantity');
$table->integer('school_id')->unsigned();
$table->bigInteger('school_id')->unsigned();
$table->date('issue_date');
$table->date('return_date');
$table->decimal('fine');
$table->tinyInteger('borrowed');
$table->integer('user_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->foreign('student_code')->references('student_code')->on('users');
$table->foreign('book_id')->references('id')->on('books');
$table->foreign('school_id')->references('id')->on('schools');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Expand Down
Loading