Skip to content

Commit

Permalink
Modified Database
Browse files Browse the repository at this point in the history
  • Loading branch information
meowfu0 committed Sep 23, 2024
1 parent 52593d5 commit ef5c287
Show file tree
Hide file tree
Showing 13 changed files with 782 additions and 25 deletions.
37 changes: 24 additions & 13 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,13 @@
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use App\Models\Course; // Add this line to import the Course model
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;

class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/

use RegistersUsers;

/**
Expand All @@ -41,6 +31,17 @@ public function __construct()
$this->middleware('guest');
}

/**
* Show the registration form.
*
* @return \Illuminate\View\View
*/
public function showRegistrationForm()
{
$courses = Course::all(); // Fetch all courses
return view('auth.register', compact('courses')); // Pass to the view
}

/**
* Get a validator for an incoming registration request.
*
Expand All @@ -50,7 +51,12 @@ public function __construct()
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'phone_number' => ['required', 'string', 'max:15'],
'course_bloc' => ['required', 'in:A,B,C,D,E,F'], // Updated from 'block' to 'course_bloc'
'course_id' => ['required', 'exists:courses,id'],
'year' => ['required', 'in:1st,2nd,3rd,4th,5th'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
Expand All @@ -65,7 +71,12 @@ protected function validator(array $data)
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'phone_number' => $data['phone_number'],
'course_bloc' => $data['course_bloc'], // Updated from 'block' to 'course_bloc'
'course_id' => $data['course_id'],
'year' => $data['year'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
Expand Down
27 changes: 27 additions & 0 deletions app/Models/Course.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Course extends Model
{
use HasFactory;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['course_name']; // Add other fields if your table has more columns

/**
* Define the relationship with the User model.
* A course can have many users.
*/
public function users()
{
return $this->hasMany(User::class);
}
}
12 changes: 9 additions & 3 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class User extends Authenticatable
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'first_name', 'last_name', 'phone_number', 'course_bloc', 'course_id', 'year', 'email', 'password',
];

/**
Expand All @@ -41,4 +39,12 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];

/**
* Relationship to the Course model.
*/
public function course()
{
return $this->belongsTo(Course::class);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"doctrine/dbal": "^3.9",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.75",
Expand Down
Loading

0 comments on commit ef5c287

Please sign in to comment.