Projet gestion de l'école ( EduManage ) réalisé par :AIT-TALB Younes
Le code source est disponible sur github : EduManage
Description du projet
Fonctionnalités :
Authentification :
Les utilisateurs peuvent s'inscrire et se connecter avec différents rôles : étudiant, professeur, directeur ou superadministrateur.
Gestion des utilisateurs :
Le superadministrateur peut activer et désactiver les directeurs, ainsi que les supprimer. Il peut également ajouter de nouvelles écoles et afficher la liste des directeurs et des écoles.
Le directeur activé peut activer et désactiver les professeurs et les étudiants, ainsi que les supprimer. Il peut également gérer les groupes, les modules et les options de son école.
Les professeurs activés peuvent gérer les examens, y compris les lister, les ajouter, les mettre à jour et les supprimer.
Gestion des profils :
Tous les utilisateurs peuvent mettre à jour leurs détails de profil et se déconnecter.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('roles', function (Blueprint $table) {
$table->id('idRole');
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('roles');
}
};
php artisan make:migration create_schools_table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('schools', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('picture');
$table->string('address');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('schools');
}
};
create_users_table.php ( existe déjà dans le fichier de migration vous n'êtes pas obligé de le créer il suffit de mettre à jour la fonction up)
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('firstName');
$table->string('lastName');
$table->string('email')->unique();
$table->string('picture');
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->integer('active')->default(0);
$table->unsignedBigInteger('school_id');
$table->foreign('school_id')->references('id')->on('schools');
$table->unsignedBigInteger('idRole');
$table->foreign('idRole')->references('idRole')->on('roles');
$table->rememberToken();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('users');
}
};
php artisan make:migration create_groups_table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('groups', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description');
$table->unsignedBigInteger('school_id');
$table->foreign('school_id')->references('id')->on('schools');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('groups');
}
};
php artisan make:migration create_students_table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('students', function (Blueprint $table) {
$table->id();
$table->string('CNE');
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('group_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('students');
}
};
php artisan make:migration create_options_table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('options', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->unsignedBigInteger('school_id');
$table->foreign('school_id')->references('id')->on('schools')->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('options');
}
};
php artisan make:migration create_modules_table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('modules', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('numberOfHours');
$table->unsignedBigInteger('group_id');
$table->unsignedBigInteger('option_id');
$table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade');
$table->foreign('option_id')->references('id')->on('options')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('modules');
}
};
php artisan make:migration create_exams_table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('exams', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->decimal('mark');
$table->unsignedBigInteger('student_id');
$table->foreign('student_id')->references('id')->on('students')->onDelete('cascade');
$table->unsignedBigInteger('module_id')
$table->foreign('module_id')->references('id')->on('modules')->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('exams');
}
};
Models :
php artisan make:model Role
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
use HasFactory;
protected $primaryKey = 'id';
protected $table = 'roles';
protected $fillable = ['name'];
public function users () {
return $this->hasMany(User::class,'idRole');
}
}
php artisan make:model School
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class School extends Model
{
use HasFactory;
protected $primaryKey = 'id';
protected $table = 'schools';
protected $fillable = ['name', 'picture', 'address'];
public function users()
{
return $this->hasMany(User::class);
}
public function directors()
{
return $this->users()->where('idRole', 1);
}
public function group() {
return $this->hasMany(Group::class);
}
public function option () {
return $this->hasMany(Option::class);
}
}
User (Le modèle utilisateur est déjà créé dans le dossier models, vous n'avez pas besoin de le créer, il suffit de mettre à jour le contenu)
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'firstName',
'lastName',
'email',
'picture',
'password',
'idRole',
'school_id',
'active',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
public function student()
{
return $this->hasOne(Student::class, 'user_id', 'id');
}
public function role () {
return $this->belongsTo(Role::class, 'idRole','idRole');
}
public function school()
{
return $this->belongsTo(School::class);
}
}
php artisan make:model Group
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Group extends Model
{
use HasFactory;
protected $table = 'groups';
protected $primaryKey = 'id';
protected $fillable = ['name', 'description', 'school_id'];
public function student () {
return $this->hasMany(Student::class);
}
public function module () {
return $this->hasMany(Module::class);
}
public function school () {
return $this->belongsTo(School::class);
}
}
php artisan make:model Student
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Student extends Model
{
use HasFactory;
protected $primaryKey = 'id';
protected $table = 'students';
protected $fillable = ['user_id','CNE', 'group_id'];
public function user () {
return $this->belongsTo(User::class);
}
public function exam () {
return $this->hasMany(Exam::class);
}
public function group() {
return $this->belongsTo(Group::class);
}
}
php artisan make:model Option
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Option extends Model
{
use HasFactory;
protected $table = 'options';
protected $primaryKey = 'id';
protected $fillable = ['name', 'school_id'];
public function module () {
return $this->hasMany(Module::class);
}
public function school () {
return $this->belongsTo(School::class);
}
}
php artisan make:model Module
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Module extends Model
{
use HasFactory;
protected $table = 'modules';
protected $primaryKey = 'id';
protected $fillable = [
'name', 'numberOfHours', 'group_id', 'option_id'
];
public function group () {
return $this->belongsTo(Group::class);
}
public function option () {
return $this->belongsTo(Option::class);
}
public function exam () {
return $this->hasMany(Exam::class);
}
}
php artisan make:model Exam
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Exam extends Model
{
use HasFactory;
protected $table = 'exams';
protected $primaryKey = 'id';
protected $fillable = [
'name', 'mark' , 'student_id' , 'module_id'
];
public function student() {
return $this->belongsTo(Student::class);
}
public function module () {
return $this->belongsTo(Module::class);
}
}
Controllers :
Auth/RegisterController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\Group;
use App\Models\Role;
use App\Models\Student;
use App\Models\User;
use App\Models\School;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
public function showRegister()
{
$rolesList = Role::all();
$schoolsList = School::all();
$groupsList = Group::all();
return view('auth.register', ['rolesList' => $rolesList, 'schoolsList' => $schoolsList, 'groupsList' => $groupsList]);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'firstName' => ['required', 'string', 'max:255'],
'lastName' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'idRole' => ['required', 'string', 'nullable'],
'school_id' => ['required'],
'profilePicture' => ['required', 'image', 'mimes:jpg,jpeg,png', 'max:5120'],
'CNE' => ['required_if:idRole,3', 'string', 'nullable'],
'group_id' => ['required_if:idRole,3', 'string', 'nullable'],
]);
}
/**
* Handle the profile picture upload.
*
* @param \Illuminate\Http\UploadedFile $file
* @return string
*/
protected function handleUploadPicture($file)
{
$folder = 'pictures';
$token = uniqid();
$pictureSrc = $folder . '/' . $token . '-' . $file->getClientOriginalName();
$file->move(public_path($folder), $token . '-' . $file->getClientOriginalName());
return $pictureSrc;
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\Models\User
*/
protected function create(array $data)
{
$profilePictureSrc = $this->handleUploadPicture(request()->file('profilePicture'));
$role = Role::where('idRole', $data['idRole'])->firstOrFail();
$user = User::create([
'firstName' => $data['firstName'],
'lastName' => $data['lastName'],
'email' => $data['email'],
'idRole' => $data['idRole'],
'password' => Hash::make($data['password']),
'picture' => $profilePictureSrc,
'active' => 0,
'school_id' => $data['school_id']
]);
if ($role->name === 'Student') {
Student::create([
'user_id' => $user->id,
'CNE' => $data['CNE'],
'group_id' => $data['group_id'],
]);
}
return $user;
}
}
Auth/LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
php artisan make:controller UserController
permet aux utilisateurs de mettre à jour les détails de leur profil et permet à l'administrateur d'activer et de désactiver les directeurs et également de les supprimer
<?php
namespace App\Http\Controllers;
use App\Models\Role;
use App\Models\Student;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
protected function handleUploadPicture($file)
{
$folder = 'pictures';
$token = uniqid();
$pictureSrc = $folder . '/' . $token . '-' . $file->getClientOriginalName();
$file->move(public_path($folder), $token . '-' . $file->getClientOriginalName());
return $pictureSrc;
}
public function deactivateDirector($id)
{
$director = User::find($id);
$director->active = 0;
$director->save();
return redirect()->back()->with('success', 'Director desactivated successfully');
}
public function activateDirector($id)
{
$director = User::find($id);
$director->active = 1;
$director->save();
return redirect()->back()->with('success', 'Director activated successfully');
}
public function destroy(User $user, Student $student = null)
{
$currentUser = Auth::user();
if($currentUser->role->name === "Student"){
$student->delete();
return redirect()->back()->with('success', 'User deleted successfully');
}else {
$user->delete();
}
return redirect()->back()->with('success', 'User deleted successfully');
}
public function modifyUser(User $user)
{
return view('user.update', compact('user'));
}
public function update(Request $request, User $user)
{
$validatedData = $request->validate([
'firstName' => ['string', 'max:255'],
'lastName' => ['string', 'max:255'],
'email' => ['string', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
'password' => ['string', 'min:8', 'nullable'],
'idRole' => ['string', 'max:255', 'exists:roles,idRole'],
'profilePicture' => ['nullable', 'image', 'mimes:jpg,jpeg,png', 'max:5120'],
'CNE' => ['required_if:idRole,Student', 'string', 'nullable']
]);
if ($request->hasFile('profilePicture')) {
$validatedData['profilePicture'] = $this->handleUploadPicture($request->file('profilePicture'));
$user->picture = $validatedData['profilePicture'];
$user->save();
}
if (empty($validatedData['password'])) {
unset($validatedData['password']);
} else {
$validatedData['password'] = Hash::make($validatedData['password']);
}
$user->update($validatedData);
if ($request->idRole === 'Student') {
if ($user->student) {
$user->student->update(['CNE' => $validatedData['CNE']]);
} else {
Student::create(['user_id' => $user->id, 'CNE' => $validatedData['CNE']]);
}
}
return redirect()->route('home')->with('success', 'User details updated successfully');
}
}
Mettre à jour les informations
Activer, Desactiver, Supprimer directeur
php artisan make:controller DirectorController
permet aux directeurs de voir la liste des professeurs et la liste des étudiants dans leur annonce scolaire et d'activer et de désactiver l'étudiant ou le professeur
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
class DirectorController extends Controller
{
public function showDirectorsList()
{
if (Auth::user()->role->name === "sysAdmin") {
$directeursList = User::join('roles', 'users.idRole', '=', 'roles.idRole')
->where('roles.name', 'Director')
->get();
return view("admin.directeursList", compact('directeursList'));
} else {
return redirect("/home");
}
}
public function showProfessorsList()
{
if (Auth::user()->role->name === "Director") {
$directorSchoolId = Auth::user()->school_id;
$professorsList = User::select('users.id', 'users.firstName', 'users.lastName', 'users.email', 'users.active', 'schools.name as school_name', 'roles.name as role_name')
->join('roles', 'users.idRole', '=', 'roles.idRole')
->join('schools', 'users.school_id', '=', 'schools.id')
->where('roles.name', 'Professor')
->where('schools.id', $directorSchoolId)
->get();
return view("professor.professorsList", compact('professorsList'));
} else {
return redirect("/home");
}
}
public function showStudentsList () {
if (Auth::user()->role->name === "Director") {
$directorSchoolId = Auth::user()->school_id;
$studentsList = User::join('roles', 'users.idRole', '=', 'roles.idRole')
->join('schools', 'users.school_id', '=', 'schools.id')
->join('students', 'users.id', '=', 'students.user_id')
->where('roles.name', 'Student')
->where('schools.id', $directorSchoolId)
->with('school', 'student')
->get();
return view("student.studentsList", compact('studentsList'));
} else {
return redirect("/home");
}
}
public function deactivateStudentOrProfessor($id)
{
$studentOrProfessor = User::find($id);
if ($studentOrProfessor) {
$studentOrProfessor->active = 0;
$studentOrProfessor->save();
return redirect()->back()->with('success', 'User deactivated successfully');
}
return redirect()->back()->with('error', 'User not found');
}
public function activateStudentOrProfessor($id)
{
$studentOrProfessor = User::find($id);
if ($studentOrProfessor) {
$studentOrProfessor->active = 1;
$studentOrProfessor->save();
return redirect()->back()->with('success', 'User activated successfully');
}
return redirect()->back()->with('error', 'User not found');
}
}
Lister, Activer, Desactiver, Professeur ou Etudiant
php artisan make:controller GroupController
permet au directeur d'ajouter, de mettre à jour, de lister et de supprimer les groupes liés à son école
<?php
namespace App\Http\Controllers;
use App\Models\Group;
use App\Models\School;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class GroupController extends Controller
{
public function showGroupsList () {
$schoolId = Auth::user()->school_id;
$groupsList = Group::where('school_id', $schoolId)->get();
return view('group.groupsList', compact('groupsList'));
}
public function destroyGroup(Group $group) {
$schoolId = Auth::user()->school_id;
$userRole = Auth::user()->role->name;
if ($userRole === 'Director' && Auth::user()->active === 1) {
if ($group->school_id == $schoolId) {
$group->delete();
return back()->with('success', 'Group deleted successfully');
}
return back()->with('error', 'You do not have permission to delete this group');
}
return back()->with('error', 'You do not have permission to delete this group');
}
public function createGroup () {
return view('group.create');
}
public function storeGroup (Request $request) {
$schoolId = Auth::user()->school_id;
$validatedData = $request->validate([
'name' => 'required|string|max:255',
'description' => 'required|string',
]);
Group::create([
'name' => $validatedData['name'],
'description' => $validatedData['description'],
'school_id' => $schoolId,
]);
return redirect()->route('director.showGroupsList')->with('success', 'Group created successfully');
}
public function editGroup (Group $group){
return view('group.edit', compact('group'));
}
public function updategroup(Request $request, Group $group){
$validatedData = $request->validate([
'name' => 'required|string|max:255',
'description' => 'required|string',
]);
$group->update([
'name' => $validatedData['name'],
'description' => $validatedData['description']
]);
return redirect()->route('director.showGroupsList')->with('success', 'Group updated successfully');
}
}
Lister les group
Ajouter group
Modifier group
php artisan make:controller OptionController
permet au directeur d'ajouter, de mettre à jour, de lister et de supprimer les option liés à son école
<?php
namespace App\Http\Controllers;
use App\Models\Option;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use PhpParser\Node\Expr\FuncCall;
class OptionController extends Controller
{
public function showOptionsList () {
$schoolId = Auth::user()->school_id;
$optionsList = Option::where('school_id', $schoolId)->get();
return view('option.optionList', compact('optionsList'));
}
public function createOption () {
return view('option.create');
}
public function storeOption (Request $request) {
$schoolId = Auth::user()->school_id;
$validatedData = $request->validate([
'name' => 'required|string'
]);
Option::create([
'name'=>$validatedData['name'],
'school_id' => $schoolId
]);
return redirect()->route('director.showOptionsList')->with('success', 'Option created successfully');
}
public function editOption (Option $option) {
return view('option.edit', compact('option'));
}
public function updateOption(Request $request, Option $option){
$validatedData = $request->validate([
'name' => 'required|string|max:255',
]);
$option->update([
'name' => $validatedData['name'],
]);
return redirect()->route('director.showOptionsList')->with('success', 'Option updated successfully');
}
public function destroyOption(Option $option) {
$schoolId = Auth::user()->school_id;
$userRole = Auth::user()->role->name;
if ($userRole === 'Director' && Auth::user()->active === 1) {
if ($option->school_id == $schoolId) {
$option->delete();
return back()->with('success', 'Option deleted successfully');
}
return back()->with('error', 'You do not have permission to delete this Option');
}
return back()->with('error', 'You do not have permission to delete this Option');
}
}
Liste des Options
Ajouter Option
Modifier Option
php artisan make:controller ModuleController
permet au directeur d'ajouter, de mettre à jour, de lister et de supprimer les modules liés à son école
<?php
namespace App\Http\Controllers;
use App\Models\Group;
use App\Models\Module;
use App\Models\Option;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ModuleController extends Controller
{
public function showModulesList () {
$schoolId = Auth::user()->school_id;
$optionID = Option::where('school_id', $schoolId)->value('id');
$modulesList = Module::where('option_id', $optionID)->get();
return view('module.modulesList', compact('modulesList'));
}
public function createModule () {
$schoolId = Auth::user()->school_id;
$optionsList = Option::where('school_id', $schoolId)->get();
$groupsList = Group::where('school_id', $schoolId)->get();
return view('module.create', ['optionsList'=>$optionsList, 'groupsList'=>$groupsList]);
}
public function storeModule (Request $request) {
$validatedData = $request->validate([
'name' => ['required', 'string'],
'numberOfHours' => ['required', 'integer'],
'option_id' => ['required', 'exists:options,id'],
'group_id' => ['required', 'exists:groups,id']
]);
Module::create([
'name' =>$validatedData['name'],
'numberOfHours' =>$validatedData['numberOfHours'],
'option_id' => $validatedData['option_id'],
'group_id' => $validatedData['group_id']
]);
return redirect()->route('director.showModulesList')->with('success', 'Module created successfully');
}
public function editModule (Module $module) {
$schoolId = Auth::user()->school_id;
$optionsList = Option::where('school_id', $schoolId)->get();
$groupsList = Group::where('school_id', $schoolId)->get();
return view('module.edit', ['optionsList' => $optionsList, 'groupsList' => $groupsList, 'module' => $module]);
}
public function updateModule(Request $request, Module $module)
{
$validatedData = $request->validate([
'name' => ['required', 'string'],
'numberOfHours' => ['required', 'integer'],
'option_id' => ['required', 'exists:options,id'],
'group_id' => ['required', 'exists:groups,id']
]);
$module->update($validatedData);
return redirect()->route('director.showModulesList')->with('success', 'Module updated successfully');
}
public function destroyModule (Module $module) {
$module->delete();
return redirect()->route('director.showModulesList')->with('success', 'Module deleted successfully');
}
}
Liste des Module
Ajouter Module
Modifier Module
php artisan make:controller SchoolController
permet au System administrateur d'ajouter, de mettre à jour, de voir les details, de lister et de supprimer les Ecoles
<?php
namespace App\Http\Controllers;
use App\Models\School;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class SchoolController extends Controller
{
protected function handleUploadPicture($file)
{
$folder = 'pictures';
$token = uniqid();
$pictureSrc = $folder . '/' . $token . '-' . $file->getClientOriginalName();
$file->move(public_path($folder), $token . '-' . $file->getClientOriginalName());
return $pictureSrc;
}
public function showSchoolsList()
{
if (Auth::user()->role->name === "sysAdmin") {
$schoolsList = School::all();
return view("admin.schoolsList", compact('schoolsList'));
} else {
return redirect("/home");
}
}
public function destroySchool(School $school)
{
$school->delete();
return redirect()->back()->with('success', 'School deleted successfully');
}
public function createSchool()
{
return view('school.create');
}
public function storeSchool(Request $request)
{
$validatedData = $request->validate([
'schoolName' => ['required', 'string', 'max:255'],
'schoolAddress' => ['required', 'string', 'max:255'],
'schoolPicture' => ['required', 'image', 'mimes:jpg,jpeg,png', 'max:5120'],
]);
$picturePath = $this->handleUploadPicture($request->file('schoolPicture'));
School::create([
'name' => $validatedData['schoolName'],
'address' => $validatedData['schoolAddress'],
'picture' => $picturePath,
]);
return redirect()->route('admin.schoolsList')->with('success', 'School created successfully');
}
public function modifySchool(School $school)
{
return view('school.update', compact('school'));
}
public function updateSchool(Request $request, School $school)
{
$validatedData = $request->validate([
'schoolName' => ['required', 'string', 'max:255'],
'schoolAddress' => ['required', 'string', 'max:255'],
'schoolPicture' => ['nullable', 'image', 'mimes:jpg,jpeg,png', 'max:5120'],
]);
if ($request->hasFile('schoolPicture')) {
$validatedData['schoolPicture'] = $this->handleUploadPicture($request->file('schoolPicture'));
} else {
unset($validatedData['schoolPicture']);
}
$school->update([
'name' => $validatedData['schoolName'],
'address' => $validatedData['schoolAddress'],
'picture' => $validatedData['schoolPicture'] ?? $school->picture,
]);
return redirect()->route('admin.schoolsList')->with('success', 'School updated successfully');
}
public function schoolDetails(School $school)
{
$school->load('directors');
return view('school.details', compact('school'));
}
}
Liste des Ecole
Ajouter Ecole
Modifier Ecole
Details Ecole
php artisan make:controller ExamController
permet au professeur d'ajouter, de mettre à jour, de lister et de supprimer les exam lié à son école
<?php
namespace App\Http\Controllers;
use App\Models\Exam;
use App\Models\Group;
use App\Models\Module;
use App\Models\Student;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ExamController extends Controller
{
public function showExamsList() {
$professorSchoolId = Auth::user()->school->id;
$groupIds = Group::where('school_id', $professorSchoolId)->pluck('id');
$moduleIds = Module::whereIn('group_id', $groupIds)->pluck('id');
$exams = Exam::whereIn('module_id', $moduleIds)->with('student.user')->get();
return view('exam.examsList', compact('exams'));
}
public function createExam () {
$professorSchoolId = Auth::user()->school->id;
$groups = Group::where('school_id', $professorSchoolId)->get();
$modules = Module::whereIn('group_id', $groups->pluck('id'))->get();
$students = Student::whereIn('group_id', $groups->pluck('id'))
->with('user')
->get();
return view('exam.create', compact('modules', 'students'));
}
public function storeExam (Request $request){
$validatedData = $request->validate([
'name' => 'required|string|max:255',
'mark' => 'required|numeric|min:0',
'student_id' => 'required|exists:students,id',
'module_id' => 'required|exists:modules,id',
]);
Exam::create($validatedData);
return redirect()->route('professor.showExamsList')->with('success', 'Exam created successfully');
}
public function editExam (Exam $exam) {
$professorSchoolId = Auth::user()->school->id;
$groups = Group::where('school_id', $professorSchoolId)->get();
$modules = Module::whereIn('group_id', $groups->pluck('id'))->get();
$students = Student::whereIn('group_id', $groups->pluck('id'))
->with('user')
->get();
return view('exam.edit', compact('exam', 'modules', 'students'));
}
public function updateExam (Request $request, Exam $exam) {
$validatedData = $request->validate([
'name' => 'required|string|max:255',
'mark' => 'required|numeric|min:0',
'student_id' => 'required|exists:students,id',
'module_id' => 'required|exists:modules,id',
]);
$exam->update($validatedData);
return redirect()->route('professor.showExamsList')->with('success', 'Exam updated successfully.');
}
public function destroyExam (Exam $exam){
$exam->delete();
return redirect()->route('professor.showExamsList')->with('success', 'Exam deleted successfully.');
}
}
Liste des Exam
Ajouter Exam
Modifier Exam
Middlewares :
php artisan make:middleware AdminMiddleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class AdminMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::check() && Auth::user()->idRole === 4 && Auth::user()->active === 1) {
return $next($request);
}
return redirect('/home');
}
}
php artisan make:middleware DirectorMiddleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class DirectorMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::check() && Auth::user()->idRole === 1 && Auth::user()->active === 1) {
return $next($request);
}
return redirect('/home');
}
}
php artisan make:middleware ProfessorMidlleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\Auth;
class ProfessorMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::check() && Auth::user()->idRole === 2 && Auth::user()->active === 1) {
return $next($request);
}
return redirect('/home');
}
}
Routes :
web.php
<?php
use App\Http\Controllers\Auth\RegisterController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\SchoolController;
use App\Http\Controllers\DirectorController;
use App\Http\Controllers\ExamController;
use App\Http\Controllers\GroupController;
use App\Http\Controllers\ModuleController;
use App\Http\Controllers\OptionController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
// Public Routes
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
// User Registration
Route::get('/registerUser', [RegisterController::class, 'showRegister'])->name('showregister');
// Admin Routes
Route::prefix('admin')->middleware(['auth', \App\Http\Middleware\AdminMiddleware::class])->group(function () {
// User Management
Route::delete('/users/{user}/delete', [UserController::class, 'destroy'])->name('admin.deleteUser');
Route::post('/directors/{id}/activate', [UserController::class, 'activateDirector'])->name('admin.activateDirector');
Route::post('/directors/{id}/deactivate', [UserController::class, 'deactivateDirector'])->name('admin.deactivateDirector');
// School Management
Route::get('/schools', [SchoolController::class, 'showSchoolsList'])->name('admin.schoolsList');
Route::delete('/schools/{school}', [SchoolController::class, 'destroySchool'])->name('admin.destroySchool');
Route::get('/school/create', [SchoolController::class, 'createSchool'])->name('admin.createSchool');
Route::post('/school/create', [SchoolController::class, 'storeSchool'])->name('admin.storeSchool');
Route::get('/school/{school}/update', [SchoolController::class, 'modifySchool'])->name('admin.modifySchool');
Route::put('/school/{school}/update', [SchoolController::class, 'updateSchool'])->name('admin.updateSchool');
Route::get('/school/{school}/details', [SchoolController::class, 'schoolDetails'])->name('admin.schoolDetails');
// Director Management
Route::get('/directors', [DirectorController::class, 'showDirectorsList'])->name('admin.directorsList');
});
// User Routes
Route::middleware('auth')->group(function () {
Route::get('/users/{user}/update', [UserController::class, 'modifyUser'])->name('user.modifyUser');
Route::put('/users/update/{user}', [UserController::class, 'update'])->name('user.update');
});
// Director Routes
Route::prefix('director')->middleware(['auth', \App\Http\Middleware\DirectorMiddleware::class])->group(function () {
// Activate / Deactivate Student and Professor
Route::post('/users/{id}/activate', [DirectorController::class, 'activateStudentOrProfessor'])->name('director.activateStudentOrProfessor');
Route::post('/users/{id}/deactivate', [DirectorController::class, 'deactivateStudentOrProfessor'])->name('director.deactivateStudentOrProfessor');
// User Management
Route::delete('/users/{user}/delete', [UserController::class, 'destroy'])->name('admin.deleteUser');
// Professor Management
Route::get('/professors', [DirectorController::class, 'showProfessorsList'])->name('director.showProfessorsList');
// Student Management
Route::get('/students', [DirectorController::class, 'showStudentsList'])->name('director.showStudentsList');
// Group Management
Route::get('/groups', [GroupController::class, 'showGroupsList'])->name('director.showGroupsList');
Route::get('/groups/create', [GroupController::class, 'createGroup'])->name('director.createGroup');
Route::post('/groups/create', [GroupController::class, 'storeGroup'])->name('director.storeGroup');
Route::get('/groups/{group}/update', [GroupController::class, 'editGroup'])->name('director.editGroup');
Route::put('/groups/{group}/update', [GroupController::class, 'updateGroup'])->name('director.updateGroup');
Route::delete('/groups/{group}/delete', [GroupController::class, 'destroyGroup'])->name('director.destroyGroup');
// Option Management
Route::get('/options', [OptionController::class, 'showOptionsList'])->name('director.showOptionsList');
Route::get('/options/create', [OptionController::class,'createOption'])->name('director.createOption');
Route::post('/options/create', [OptionController::class, 'storeOption'])->name('director.storeOption');
Route::get('/options/{option}/update', [OptionController::class, 'editOption'])->name('director.editOption');
Route::put('/options/{option}/update', [OptionController::class, 'updateOption'])->name('director.updateOption');
Route::delete('/options/{option}/delete', [OptionController::class, 'destroyOption'])->name('director.destroyOption');
// Modules Management
Route::get('/modules', [ModuleController::class, 'showModulesList'])->name('director.showModulesList');
Route::get('/modules/create', [ModuleController::class, 'createModule'])->name('director.createModule');
Route::post('/modules/create', [ModuleController::class, 'storeModule'])->name('director.storeModule');
Route::get('/modules/{module}/update', [ModuleController::class, 'editModule'])->name('director.editModule');
Route::put('/modules/{module}/update', [ModuleController::class, 'updateModule'])->name('director.updateModule');
Route::delete('/modules/{module}/delete', [ModuleController::class, 'destroyModule'])->name('director.deleteModule');
});
Route::prefix('professor')->middleware(['auth', \App\Http\Middleware\ProfessorMiddleware::class])->group(function () {
// Exams Management
Route::get('/exams', [ExamController::class, 'showExamsList'])->name('professor.showExamsList');
Route::get('/exam/add', [ExamController::class, 'createExam'])->name('professor.crateExam');
Route::post('/exams/add', [ExamController::class, 'storeExam'])->name('professor.storeExam');
Route::get('/exam/{exam}/edit', [ExamController::class, 'editExam'])->name('professor.editExam');
Route::put('/exam/{exam}/edit', [ExamController::class, 'updateExam'])->name('professor.updateExam');
Route::delete('/exam/{exam}/delete', [ExamController::class, 'destroyExam'])->name('professor.destroyExam');
});
// Home Route
Route::get('/home', [HomeController::class, 'index'])->name('home');