added Pivot model
This commit is contained in:
parent
8b708ab597
commit
c632489cf3
28
app/Http/Requests/ScorePostRequest.php
Normal file
28
app/Http/Requests/ScorePostRequest.php
Normal 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
11
app/Models/Score.php
Normal 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;
|
||||
}
|
@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
|
||||
class Student extends Model
|
||||
@ -31,6 +32,11 @@ class Student extends Model
|
||||
return $this->morphOne(User::class, 'userable');
|
||||
}
|
||||
|
||||
public function subjects(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Subject::class)->using(Score::class);
|
||||
}
|
||||
|
||||
public function scopeFilter(Builder $query): void
|
||||
{
|
||||
$name = request('name');
|
||||
|
@ -26,6 +26,11 @@ class Subject extends Model
|
||||
return $this->belongsToMany(Teacher::class);
|
||||
}
|
||||
|
||||
public function students(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Student::class)->using(Score::class);
|
||||
}
|
||||
|
||||
public function scopeFilter(Builder $query): void
|
||||
{
|
||||
$name = request('name');
|
||||
|
Loading…
Reference in New Issue
Block a user