Work on students pages

This commit is contained in:
Matt Young 2024-05-29 21:20:00 -05:00
parent d7c36dd5f2
commit fa524e80da
7 changed files with 63 additions and 34 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Models\Student;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@ -36,7 +37,7 @@ class StudentController extends Controller
/**
* Display the specified resource.
*/
public function show(User $user)
public function show(Request $request, Student $student)
{
//
}
@ -44,9 +45,10 @@ class StudentController extends Controller
/**
* Show the form for editing the specified resource.
*/
public function edit(User $user)
public function edit(Request $request, Student $student)
{
//
if ($request->user()->cannot('update', $student)) abort(403);
return view('students.edit', ['student' => $student]);
}
/**

View File

@ -8,6 +8,14 @@ use Illuminate\Auth\Access\Response;
class StudentPolicy
{
/**
* Grant admin users access to all functions
*/
public function before(User $user, string $ability): bool|null
{
if($user->is_admin) return true;
return null;
}
/**
* Determine whether the user can view any models.
*/
@ -37,7 +45,7 @@ class StudentPolicy
*/
public function update(User $user, Student $student): bool
{
//
return $user->school_id == $student->school_id;
}
/**

View File

@ -8,13 +8,13 @@
$topPadding = ($first) ? '':'pt-10';
@endphp
<div class="grid grid-cols-1 gap-x-8 gap-y-8 md:grid-cols-3 {{ $topPadding }}">
<div class="grid grid-cols-1 gap-x-8 gap-y-8 md:grid-cols-4 {{ $topPadding }}">
<div class="px-4 sm:px-0">
<h2 class="text-base font-semibold leading-7 text-gray-900">{{ $section_name }}</h2>
<p class="mt-1 text-sm leading-6 text-gray-600">{{ $section_description }}</p>
</div>
<div class="bg-white shadow-sm ring-1 ring-gray-900/5 sm:rounded-xl md:col-span-2">
<div class="bg-white shadow-sm ring-1 ring-gray-900/5 sm:rounded-xl md:col-span-3">
{{ $slot }}
</div>
</div>

View File

@ -10,6 +10,7 @@
submit-button-text="Create School"
method="POST"
action="/schools"
cols="9"
>
<x-auth.form-field name="name" label="School Name" div_classes="sm:col-span-6"/>
<x-auth.form-field name="address" label="School Address" div_classes="sm:col-span-6"/>

View File

@ -6,32 +6,12 @@
<x-layout.app>
<x-slot:page_title>Students</x-slot:page_title>
<x-table.container class="mx-auto max-w-2xl" x-data="data()">
<x-table.title_above_table>
<x-slot:title>Students <x-badge_pill>{{ $students->count() }}</x-badge_pill></x-slot:title>
<x-slot:subtitle>Before submitting entries, you must enter your students</x-slot:subtitle>
<x-slot:button>Add Student</x-slot:button>
</x-table.title_above_table>
<x-table.table>
<x-table.table_header_row>
<x-table.th first @click="sortByColumn" class="cursor-pointer select-none">Name</x-table.th>
<x-table.th @click="sortByColumn" class="cursor-pointer select-none">Grade</x-table.th>
<x-table.th :placeholder="true">
<span class="sr-only">Edit</span>
</x-table.th>
<x-table.body x-ref="tbody">
@foreach($students as $student)
<tr>
<x-table.td :first="true">{{ $student->full_name(true) }}</x-table.td>
<x-table.td>{{ $student->grade }}</x-table.td>
<x-table.td_right_link sr_text=", {{ $student->full_name() }}">
<x-slot:a href="/students/{{ $student->id }}/edit">Edit</x-slot:a>
</x-table.td_right_link>
</tr>
@endforeach
</x-table.body>
</x-table.table_header_row>
</x-table.table>
</x-table.container>
<x-layout.page-section>
<x-slot:section_name>Create Student</x-slot:section_name>
<x-slot:section_description>Student full names must be unique. Add a middle initial to the first name if necessary.</x-slot:section_description>
<x-auth.form-card method="POST" action="/students/create" submit-button-text="Create Student" >
<x-auth.form-field name="first_name" label="First Name" div_classes="sm:col-span-3" required />
<x-auth.form-field name="last_name" label="Last Name" div_classes="sm:col-span-3" required />
</x-auth.form-card>
</x-layout.page-section>
</x-layout.app>

View File

@ -0,0 +1,37 @@
@php use Illuminate\Support\Facades\Auth; @endphp
@push('scripts')
{{-- Code from https://codepen.io/ryangjchandler/pen/WNQQKeR--}}
<script src="{{ asset('js/sort_table_by_column.js') }}"></script>
@endpush
<x-layout.app>
<x-slot:page_title>Students</x-slot:page_title>
<x-table.container class="mx-auto max-w-2xl" x-data="data()">
<x-table.title_above_table>
<x-slot:title>Students <x-badge_pill>{{ $students->count() }}</x-badge_pill></x-slot:title>
<x-slot:subtitle>Before submitting entries, you must enter your students</x-slot:subtitle>
<x-slot:button>Add Student</x-slot:button>
</x-table.title_above_table>
<x-table.table>
<x-table.table_header_row>
<x-table.th first @click="sortByColumn" class="cursor-pointer select-none">Name</x-table.th>
<x-table.th @click="sortByColumn" class="cursor-pointer select-none">Grade</x-table.th>
<x-table.th :placeholder="true">
<span class="sr-only">Edit</span>
</x-table.th>
<x-table.body x-ref="tbody">
@foreach($students as $student)
<tr>
<x-table.td :first="true">{{ $student->full_name(true) }}</x-table.td>
<x-table.td>{{ $student->grade }}</x-table.td>
<x-table.td_right_link sr_text=", {{ $student->full_name() }}">
<x-slot:a href="/students/{{ $student->id }}/edit">Edit</x-slot:a>
</x-table.td_right_link>
</tr>
@endforeach
</x-table.body>
</x-table.table_header_row>
</x-table.table>
</x-table.container>
</x-layout.app>

View File

@ -22,6 +22,7 @@ Route::middleware(['auth','verified'])->group(function () {
// Student Related Routes
Route::middleware(['auth','verified'])->controller(StudentController::class)->group(function() {
Route::get('/students','index');
Route::get('/students/{student}/edit','edit');
});