From 5debf0f0fa13755933397006d2bf1b0f984e3535 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Wed, 29 May 2024 07:32:39 -0500 Subject: [PATCH] Work on students --- app/Models/Student.php | 6 ++++++ resources/views/students/index.blade.php | 2 ++ 2 files changed, 8 insertions(+) diff --git a/app/Models/Student.php b/app/Models/Student.php index c821523..03fabf4 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -5,6 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasManyThrough; class Student extends Model { @@ -15,4 +16,9 @@ class Student extends Model return $this->belongsTo(School::class); } + public function users(): HasManyThrough + { + return $this->hasManyThrough(User::class, School::class); + } + } diff --git a/resources/views/students/index.blade.php b/resources/views/students/index.blade.php index a88bd57..c807e7c 100644 --- a/resources/views/students/index.blade.php +++ b/resources/views/students/index.blade.php @@ -1,3 +1,5 @@ +@php use Illuminate\Support\Facades\Auth; @endphp Students + {{ dd(Auth::user()->students) }}