added Pivot model

This commit is contained in:
m.zargarov 2024-05-07 17:15:58 +04:00
parent 8b708ab597
commit c632489cf3
4 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ScorePostRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}

11
app/Models/Score.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\Pivot;
class Score extends Pivot
{
use HasFactory;
}

View File

@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphOne;
class Student extends Model class Student extends Model
@ -31,6 +32,11 @@ class Student extends Model
return $this->morphOne(User::class, 'userable'); return $this->morphOne(User::class, 'userable');
} }
public function subjects(): BelongsToMany
{
return $this->belongsToMany(Subject::class)->using(Score::class);
}
public function scopeFilter(Builder $query): void public function scopeFilter(Builder $query): void
{ {
$name = request('name'); $name = request('name');

View File

@ -26,6 +26,11 @@ class Subject extends Model
return $this->belongsToMany(Teacher::class); return $this->belongsToMany(Teacher::class);
} }
public function students(): BelongsToMany
{
return $this->belongsToMany(Student::class)->using(Score::class);
}
public function scopeFilter(Builder $query): void public function scopeFilter(Builder $query): void
{ {
$name = request('name'); $name = request('name');