Admin Entries Page Working
This commit is contained in:
parent
ddcf4a46c4
commit
ddb5b7a71e
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Audition;
|
||||
use App\Models\Entry;
|
||||
use App\Models\School;
|
||||
use App\Models\Student;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class EntryController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
$entries = Entry::with(['student.school','audition'])->orderBy('created_at','DESC')->paginate(10);
|
||||
return view('admin.entries.index', ['entries' => $entries] );
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
$students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get();
|
||||
$auditions = Audition::orderBy('name')->get();
|
||||
return view('admin.entries.create', ['students' => $students, 'auditions' => $auditions]);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
request()->validate([
|
||||
'student_id' => ['required', 'exists:students,id'],
|
||||
'audition_id' => ['required', 'exists:auditions,id'],
|
||||
]);
|
||||
|
||||
Entry::create([
|
||||
'student_id' => request('student_id'),
|
||||
'audition_id' => request('audition_id'),
|
||||
]);
|
||||
|
||||
return redirect('/admin/entries');
|
||||
}
|
||||
|
||||
public function edit(Entry $entry)
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
$students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get();
|
||||
$auditions = Audition::orderBy('name')->get();
|
||||
return view('admin.entries.edit', ['entry' => $entry, 'students' => $students, 'auditions' => $auditions]);
|
||||
}
|
||||
|
||||
public function update(Entry $entry)
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
request()->validate([
|
||||
'student_id' => ['required', 'exists:students,id'],
|
||||
'audition_id' => ['required', 'exists:auditions,id'],
|
||||
]);
|
||||
|
||||
$entry->update([
|
||||
'student_id' => request('student_id'),
|
||||
'audition_id' => request('audition_id'),
|
||||
]);
|
||||
|
||||
return redirect('/admin/entries');
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ class SchoolController extends Controller
|
|||
public function index()
|
||||
{
|
||||
if (! Auth::user()->is_admin) abort(403);
|
||||
$schools = School::orderBy('name')->get();
|
||||
$schools = School::with(['users','students','entries'])->orderBy('name')->get();
|
||||
return view('admin.schools.index', ['schools' => $schools]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class StudentController extends Controller
|
|||
public function index()
|
||||
{
|
||||
if (! Auth::user()->is_admin) abort(403);
|
||||
$students = Student::orderBy('last_name')->orderBy('first_name')->paginate(15);
|
||||
$students = Student::with(['school','entries'])->orderBy('last_name')->orderBy('first_name')->paginate(15);
|
||||
return view('admin.students.index', ['students' => $students]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class UserController extends Controller
|
|||
public function index()
|
||||
{
|
||||
if (! Auth::user()->is_admin) abort(403);
|
||||
$users = User::orderBy('last_name')->orderBy('first_name')->get();
|
||||
$users = User::with('school')->orderBy('last_name')->orderBy('first_name')->get();
|
||||
return view('admin.users.index', ['users' => $users]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,4 +20,6 @@ class Audition extends Model
|
|||
{
|
||||
return Audition::where('entry_deadline', '>=', now())->get();
|
||||
}
|
||||
|
||||
// TODO add order column to be able to sort in score order
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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\HasOneThrough;
|
||||
|
||||
class Entry extends Model
|
||||
{
|
||||
|
|
@ -20,4 +21,9 @@ class Entry extends Model
|
|||
{
|
||||
return $this->belongsTo(Audition::class);
|
||||
}
|
||||
|
||||
public function school(): HasOneThrough
|
||||
{
|
||||
return $this->hasOneThrough(School::class, Student::class, 'id', 'id', 'student_id', 'school_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,13 @@ class School extends Model
|
|||
|
||||
public function entries(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Entry::class,Student::class);
|
||||
return $this->hasManyThrough(
|
||||
Entry::class,
|
||||
Student::class,
|
||||
'school_id',
|
||||
'student_id',
|
||||
'id',
|
||||
'id');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
<x-layout.app>
|
||||
<x-card.card class="mx-auto max-w-2xl">
|
||||
<x-card.heading>Create Entry</x-card.heading>
|
||||
<x-form.form method="POST" action="/admin/entries">
|
||||
<x-form.body-grid columns="3">
|
||||
|
||||
<x-form.select name="student_id" colspan="2">
|
||||
<x-slot:label>Student</x-slot:label>
|
||||
@foreach ($students as $student)
|
||||
|
||||
<option value="{{ $student->id }}">{{ $student->full_name(true) }} - {{ $student->school->name }} (Grade {{ $student->grade }})</option>
|
||||
@endforeach
|
||||
|
||||
</x-form.select><x-form.select name="audition_id" colspan="1">
|
||||
<x-slot:label>Audition</x-slot:label>
|
||||
@foreach ($auditions as $audition)
|
||||
|
||||
<option value="{{ $audition->id }}"> {{ $audition->name }}</option>
|
||||
@endforeach
|
||||
</x-form.select>
|
||||
</x-form.body-grid>
|
||||
<x-form.footer>
|
||||
<x-form.button>Create Entry</x-form.button>
|
||||
</x-form.footer>
|
||||
</x-form.form>
|
||||
</x-card.card>
|
||||
</x-layout.app>
|
||||
|
||||
{{--TODO apply javascript to only show appropriate auditions for the students grade--}}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<x-layout.app>
|
||||
<x-card.card class="mx-auto max-w-2xl">
|
||||
<x-card.heading>Edit Entry #{{ $entry->id }}</x-card.heading>
|
||||
<x-form.form method="PATCH" action="/admin/entries/{{ $entry->id }}">
|
||||
<x-form.body-grid columns="3">
|
||||
|
||||
<x-form.select name="student_id" colspan="2">
|
||||
<x-slot:label>Student</x-slot:label>
|
||||
@foreach ($students as $student)
|
||||
|
||||
<option value="{{ $student->id }}" {{ ($student->id == $entry->student_id ? 'selected':'') }}>
|
||||
{{ $student->full_name(true) }} - {{ $student->school->name }} (Grade {{ $student->grade }})
|
||||
</option>
|
||||
|
||||
@endforeach
|
||||
|
||||
</x-form.select><x-form.select name="audition_id" colspan="1">
|
||||
<x-slot:label>Audition</x-slot:label>
|
||||
@foreach ($auditions as $audition)
|
||||
|
||||
<option value="{{ $audition->id }}" {{ ($audition->id == $entry->audition_id ? 'selected':'') }}>
|
||||
{{ $audition->name }}
|
||||
</option>
|
||||
|
||||
@endforeach
|
||||
</x-form.select>
|
||||
</x-form.body-grid>
|
||||
<x-form.footer>
|
||||
<x-form.button>Create Entry</x-form.button>
|
||||
</x-form.footer>
|
||||
</x-form.form>
|
||||
</x-card.card>
|
||||
</x-layout.app>
|
||||
|
||||
{{--TODO apply javascript to only show appropriate auditions for the students grade--}}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<x-layout.app>
|
||||
<x-slot:page_title>Entry Administration</x-slot:page_title>
|
||||
|
||||
<x-card.card>
|
||||
<x-table.table with_title_area>
|
||||
<x-slot:title class="ml-3">Entries</x-slot:title>
|
||||
<x-slot:subtitle class="ml-3">Click id to edit</x-slot:subtitle>
|
||||
<x-slot:title_block_right class="mr-3">
|
||||
<x-form.button href="/admin/entries/create">New Entry</x-form.button>
|
||||
</x-slot:title_block_right>
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<x-table.th>ID</x-table.th>
|
||||
<x-table.th>Audition</x-table.th>
|
||||
<x-table.th>Student</x-table.th>
|
||||
<x-table.th>Grade</x-table.th>
|
||||
<x-table.th>School</x-table.th>
|
||||
<x-table.th>Entry Date</x-table.th>
|
||||
</tr>
|
||||
</thead>
|
||||
<x-table.body>
|
||||
@foreach($entries as $entry)
|
||||
<tr>
|
||||
<x-table.td><a href="/admin/entries/{{ $entry->id }}/edit"> {{ $entry->id }} </a></x-table.td>
|
||||
<x-table.td>{{ $entry->audition->name }}</x-table.td>
|
||||
<x-table.td>{{ $entry->student->full_name() }}</x-table.td>
|
||||
<x-table.td>{{ $entry->student->grade }}</x-table.td>
|
||||
<x-table.td>{{ $entry->student->school->name }}</x-table.td>
|
||||
<x-table.td>{{ $entry->created_at->format('m/d/Y g:i A') }}</x-table.td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</x-table.body>
|
||||
</x-table.table>
|
||||
|
||||
</x-card.card>
|
||||
<div class="mt-3 mx-3">
|
||||
{{ $entries->links('vendor.pagination.simple-audition') }}
|
||||
</div>
|
||||
</x-layout.app>
|
||||
{{--TODO add options to filter the page--}}
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
<x-layout.nav-link href="/admin/users" :active="request()->is('admin/users')">Users</x-layout.nav-link>
|
||||
<x-layout.nav-link href="/admin/schools" :active="request()->is('admin/schools')">Schools</x-layout.nav-link>
|
||||
<x-layout.nav-link href="/admin/students" :active="request()->is('admin/students')">Students</x-layout.nav-link>
|
||||
<x-layout.nav-link href="/admin/entries" :active="request()->is('admin/entries')">Entries</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>--}}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,15 @@ Route::view('/','welcome')->middleware('guest');
|
|||
Route::middleware(['auth','verified',CheckIfAdmin::class])->prefix('admin/')->group(function() {
|
||||
Route::view('/','admin.dashboard');
|
||||
|
||||
// Admin Entries Routes
|
||||
Route::prefix('entries')->controller(\App\Http\Controllers\Admin\EntryController::class)->group(function() {
|
||||
Route::get('/','index');
|
||||
Route::get('/create','create');
|
||||
Route::post('/','store');
|
||||
Route::get('/{entry}/edit','edit');
|
||||
Route::patch('/{entry}','update');
|
||||
});
|
||||
|
||||
// Admin Student Routes
|
||||
Route::prefix('students')->controller(\App\Http\Controllers\Admin\StudentController::class)->group(function() {
|
||||
Route::get('/','index');
|
||||
|
|
|
|||
Loading…
Reference in New Issue