prod #7

Merged
klllst merged 40 commits from feature/task-7 into master 2024-06-16 12:25:52 +04:00
9 changed files with 94 additions and 175 deletions
Showing only changes of commit 0485df95cf - Show all commits

View 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)
{
//
}
}

View File

@ -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');
}
}

View File

@ -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');
}
}

View File

@ -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');
}
}

View File

@ -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();
}
}

View File

@ -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();
});

View File

@ -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

View File

@ -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);