This commit is contained in:
Matt Young 2024-05-29 01:39:07 -05:00
parent a9af6aaeb0
commit faebb04d2c
7 changed files with 99 additions and 19 deletions

View File

@ -2,9 +2,66 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class StudentController extends Controller class StudentController extends Controller
{ {
// /**
* Display a listing of the resource.
*/
public function index()
{
$students = Auth::user()->students();
return view('students.index',['students' => $students]);
}
/**
* 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(User $user)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(User $user)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, User $user)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(User $user)
{
//
}
} }

View File

@ -69,6 +69,11 @@ class User extends Authenticatable implements MustVerifyEmail
return $this->belongsTo(School::class); return $this->belongsTo(School::class);
} }
public function students(): HasManyThrough
{
return $this->hasManyThrough(Student::class, School::class);
}
/** /**
* Return an array of schools using the users email domiain * Return an array of schools using the users email domiain

View File

@ -0,0 +1,6 @@
@props(['active' => false])
<a class="{{ $active ? 'bg-indigo-700' : 'hover:bg-indigo-500 hover:bg-opacity-75' }} text-white rounded-md px-3 py-2 text-sm font-medium"
aria-current="{{ $active ? 'page':'false' }}"
{{ $attributes }}
>{{ $slot }}</a>

View File

@ -14,8 +14,11 @@
<div class="hidden md:block"> <div class="hidden md:block">
<div class="ml-10 flex items-baseline space-x-4"> <div class="ml-10 flex items-baseline space-x-4">
<!-- Current: "bg-indigo-700 text-white", Default: "text-white hover:bg-indigo-500 hover:bg-opacity-75" --> <!-- Current: "bg-indigo-700 text-white", Default: "text-white hover:bg-indigo-500 hover:bg-opacity-75" -->
<a href="/dashboard" class="bg-indigo-700 text-white rounded-md px-3 py-2 text-sm font-medium" aria-current="page">Dashboard</a> <x-layout.nav-link href="/dashboard" :active="request()->is('dashboard')">Dashboard</x-layout.nav-link>
<a href="#" class="text-white hover:bg-indigo-500 hover:bg-opacity-75 rounded-md px-3 py-2 text-sm font-medium">Students</a> <x-layout.nav-link href="/students" :active="request()->is('students')">Students</x-layout.nav-link>
{{-- <a href="/dashboard" class="bg-indigo-700 text-white rounded-md px-3 py-2 text-sm font-medium" aria-current="page">Dashboard</a>--}}
{{-- <a href="/students" class="text-white hover:bg-indigo-500 hover:bg-opacity-75 rounded-md px-3 py-2 text-sm font-medium">Students</a>--}}
</div> </div>
</div> </div>
@ -137,7 +140,7 @@
<div class="space-y-1 px-2 pb-3 pt-2 sm:px-3"> <div class="space-y-1 px-2 pb-3 pt-2 sm:px-3">
<!-- Current: "bg-indigo-700 text-white", Default: "text-white hover:bg-indigo-500 hover:bg-opacity-75" --> <!-- Current: "bg-indigo-700 text-white", Default: "text-white hover:bg-indigo-500 hover:bg-opacity-75" -->
<a href="/dashboard" class="bg-indigo-700 text-white block rounded-md px-3 py-2 text-base font-medium" aria-current="page">Dashboard</a> <a href="/dashboard" class="bg-indigo-700 text-white block rounded-md px-3 py-2 text-base font-medium" aria-current="page">Dashboard</a>
<a href="#" class="text-white hover:bg-indigo-500 hover:bg-opacity-75 block rounded-md px-3 py-2 text-base font-medium">Students</a> <a href="/students" class="text-white hover:bg-indigo-500 hover:bg-opacity-75 block rounded-md px-3 py-2 text-base font-medium">Students</a>
</div> </div>
<div class="border-t border-indigo-700 pb-3 pt-4"> <div class="border-t border-indigo-700 pb-3 pt-4">
<div class="flex items-center px-5"> <div class="flex items-center px-5">

View File

@ -0,0 +1,3 @@
<x-layout.app>
<x-slot:page_title>Students</x-slot:page_title>
</x-layout.app>

View File

@ -2,12 +2,6 @@
<x-layout.app> <x-layout.app>
<x-slot:page_title>Test Page</x-slot:page_title> <x-slot:page_title>Test Page</x-slot:page_title>
<form method="POST" action="/users/32/set_school"> {{ request()->is('test') ? 'yes':'no' }}
@csrf
@method('PATCH')
<input type="text" name="school_id" value="1">
<button>Submit</button>
</form>
</x-layout.app> </x-layout.app>

View File

@ -2,23 +2,35 @@
use App\Http\Controllers\DashboardController; use App\Http\Controllers\DashboardController;
use App\Http\Controllers\SchoolController; use App\Http\Controllers\SchoolController;
use App\Http\Controllers\StudentController;
use App\Http\Controllers\UserController; use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::view('/test','test'); Route::view('/test','test')->middleware('auth','verified');
Route::get('/dashboard', [DashboardController::class, 'dashboard']);
Route::get('/profile', [DashboardController::class, 'profile']);
Route::get('/my_school', [DashboardController::class, 'my_school']);
Route::patch('/users/{user}/set_school', [UserController::class, 'set_school']);
Route::view('/','welcome')->middleware('guest'); Route::view('/','welcome')->middleware('guest');
// Dashboard Related Routes
Route::middleware(['auth','verified'])->group(function () {
Route::get('/dashboard', [DashboardController::class, 'dashboard']);
Route::get('/profile', [DashboardController::class, 'profile']);
Route::get('/my_school', [DashboardController::class, 'my_school']);
Route::patch('/users/{user}/set_school', [UserController::class, 'set_school']);
});
// Student Related Routes
Route::middleware(['auth','verified'])->controller(StudentController::class)->group(function() {
Route::get('/students','index');
});
// School Related Routes
Route::middleware(['auth','verified'])->controller(SchoolController::class)->group(function() { Route::middleware(['auth','verified'])->controller(SchoolController::class)->group(function() {
// Route::get('/my_school','my_school');
Route::get('/schools/create', 'create'); Route::get('/schools/create', 'create');
Route::post('/schools','store'); Route::post('/schools','store');
Route::get('/schools/{school}/edit','edit'); Route::get('/schools/{school}/edit','edit');