diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
new file mode 100644
index 0000000..4eb8213
--- /dev/null
+++ b/app/Http/Controllers/UserController.php
@@ -0,0 +1,64 @@
+morphOne(User::class, 'userable');
+ }
}
diff --git a/app/Models/Subject.php b/app/Models/Subject.php
index 7cc7d1d..9e92711 100644
--- a/app/Models/Subject.php
+++ b/app/Models/Subject.php
@@ -6,6 +6,7 @@ use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+use Illuminate\Database\Eloquent\Relations\MorphOne;
class Subject extends Model
{
@@ -33,4 +34,9 @@ class Subject extends Model
$query->whereRaw('name ilike ?', ["$name%"]);
});
}
+
+ public function user(): MorphOne
+ {
+ return $this->morphOne(User::class, 'userable');
+ }
}
diff --git a/app/Models/Teacher.php b/app/Models/Teacher.php
index 2a6ea4e..b5f057b 100644
--- a/app/Models/Teacher.php
+++ b/app/Models/Teacher.php
@@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+use Illuminate\Database\Eloquent\Relations\MorphOne;
class Teacher extends Model
{
@@ -26,4 +27,9 @@ class Teacher extends Model
{
return $this->belongsToMany(Grade::class);
}
+
+ public function user(): MorphOne
+ {
+ return $this->morphOne(User::class, 'userable');
+ }
}
diff --git a/app/Models/User.php b/app/Models/User.php
index 407a732..e6541ff 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -4,6 +4,7 @@ namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@@ -43,4 +44,9 @@ class User extends Authenticatable
'password' => 'hashed',
];
}
+
+ public function userable(): MorphTo
+ {
+ return $this->morphTo();
+ }
}
diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php
index d8d8ede..c965063 100644
--- a/database/migrations/0001_01_01_000000_create_users_table.php
+++ b/database/migrations/0001_01_01_000000_create_users_table.php
@@ -16,6 +16,7 @@ return new class extends Migration
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
+ $table->morphs('userable');
$table->rememberToken();
$table->timestamps();
});
diff --git a/database/migrations/2024_04_17_064554_add_foreign_key_to_users.php b/database/migrations/2024_04_17_085132_add_foreign_key_to_students.php
similarity index 79%
rename from database/migrations/2024_04_17_064554_add_foreign_key_to_users.php
rename to database/migrations/2024_04_17_085132_add_foreign_key_to_students.php
index 758992c..6670723 100644
--- a/database/migrations/2024_04_17_064554_add_foreign_key_to_users.php
+++ b/database/migrations/2024_04_17_085132_add_foreign_key_to_students.php
@@ -11,7 +11,7 @@ return new class extends Migration
*/
public function up(): void
{
- Schema::table('users', function (Blueprint $table) {
+ Schema::table('students', function (Blueprint $table) {
$table->foreignId('grade_id')->constrained('grades');
});
}
@@ -21,7 +21,7 @@ return new class extends Migration
*/
public function down(): void
{
- Schema::table('users', function (Blueprint $table) {
+ Schema::table('students', function (Blueprint $table) {
$table->dropColumn('grade_id');
});
}
diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php
deleted file mode 100644
index a9898e3..0000000
--- a/resources/views/welcome.blade.php
+++ /dev/null
@@ -1,172 +0,0 @@
-
-
-
-
-
-
- Laravel
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Documentation
-
-
- Laravel has wonderful documentation covering every aspect of the framework. Whether you are a newcomer or have prior experience with Laravel, we recommend reading our documentation from beginning to end.
-
-
-
-
-
-
-
-
-
-
-
-
-
Laracasts
-
-
- Laracasts offers thousands of video tutorials on Laravel, PHP, and JavaScript development. Check them out, see for yourself, and massively level up your development skills in the process.
-
-
-
-
-
-
-
-
-
-
-
Laravel News
-
-
- Laravel News is a community driven portal and newsletter aggregating all of the latest and most important news in the Laravel ecosystem, including new package releases and tutorials.
-
-
-
-
-
-
-
-
-
-
-
Vibrant Ecosystem
-
-
- Laravel's robust library of first-party tools and libraries, such as Forge , Vapor , Nova , Envoyer , and Herd help you take your projects to the next level. Pair them with powerful open source libraries like Cashier , Dusk , Echo , Horizon , Sanctum , Telescope , and more.
-
-
-
-
-
-
-
- Laravel v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }})
-
-
-
-
-
-
diff --git a/routes/web.php b/routes/web.php
index 7129277..d953592 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -2,11 +2,13 @@
use App\Http\Controllers\GradeController;
use App\Http\Controllers\SubjectController;
+use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
- return view('welcome');
+ return redirect()->route('grades.index');
});
Route::resource('grades', GradeController::class);
Route::resource('subjects', SubjectController::class);
+Route::resource('users', UserController::class);