prod #7
64
app/Http/Controllers/UserController.php
Normal file
64
app/Http/Controllers/UserController.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
|
||||
class Admin extends Model
|
||||
{
|
||||
@ -14,4 +15,9 @@ class Admin extends Model
|
||||
'last_name',
|
||||
'middle_name',
|
||||
];
|
||||
|
||||
public function user(): MorphOne
|
||||
{
|
||||
return $this->morphOne(User::class, 'userable');
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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');
|
||||
});
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user