Cleanup on entries page
This commit is contained in:
parent
e71919f35f
commit
220dbbcd52
|
|
@ -4,14 +4,18 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Audition;
|
use App\Models\Audition;
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
|
use App\Models\School;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use function abort;
|
||||||
|
use function sendMessage;
|
||||||
|
|
||||||
class EntryController extends Controller
|
class EntryController extends Controller
|
||||||
{
|
{
|
||||||
// TODO authorization policies
|
// TODO authorization policies
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
|
||||||
$entries = Auth::user()->entries()->with(['student','audition'])->get();
|
$entries = Auth::user()->entries()->with(['student','audition'])->get();
|
||||||
$auditions = Audition::all();
|
$auditions = Audition::all();
|
||||||
$students = Auth::user()->students;
|
$students = Auth::user()->students;
|
||||||
|
|
@ -21,6 +25,7 @@ class EntryController extends Controller
|
||||||
|
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
|
if ($request->user()->cannot('create', Entry::class)) abort(403);
|
||||||
// TODO write custom rule to verify the combination of student and audition is unique
|
// TODO write custom rule to verify the combination of student and audition is unique
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'student_id' => ['required', 'exists:students,id'],
|
'student_id' => ['required', 'exists:students,id'],
|
||||||
|
|
@ -34,4 +39,11 @@ class EntryController extends Controller
|
||||||
|
|
||||||
return redirect('/entries');
|
return redirect('/entries');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function destroy(Request $request, Entry $entry)
|
||||||
|
{
|
||||||
|
$entry->delete();
|
||||||
|
sendMessage('The ' . $entry->audition->name . 'entry for ' . $entry->student->full_name(). 'has been deleted.','success');
|
||||||
|
return redirect('/entries');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class StudentPolicy
|
||||||
*/
|
*/
|
||||||
public function update(User $user, Student $student): bool
|
public function update(User $user, Student $student): bool
|
||||||
{
|
{
|
||||||
if (Entry::where('student_id','=',$student->id)->exists()) return false; // Don't allow deletion of a student with entries
|
|
||||||
if($user->is_admin) return true;
|
if($user->is_admin) return true;
|
||||||
return $user->school_id == $student->school_id;
|
return $user->school_id == $student->school_id;
|
||||||
}
|
}
|
||||||
|
|
@ -50,6 +50,7 @@ class StudentPolicy
|
||||||
*/
|
*/
|
||||||
public function delete(User $user, Student $student): bool
|
public function delete(User $user, Student $student): bool
|
||||||
{
|
{
|
||||||
|
if (Entry::where('student_id','=',$student->id)->exists()) return false; // Don't allow deletion of a student with entries
|
||||||
return $user->school_id == $student->school_id;
|
return $user->school_id == $student->school_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,11 @@
|
||||||
</div>
|
</div>
|
||||||
<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" -->
|
||||||
<x-layout.nav-link href="/dashboard" :active="request()->is('dashboard')">Dashboard</x-layout.nav-link>
|
<x-layout.nav-link href="/dashboard" :active="request()->is('dashboard')">Dashboard</x-layout.nav-link>
|
||||||
<x-layout.nav-link href="/students" :active="request()->is('students')">Students</x-layout.nav-link>
|
<x-layout.nav-link href="/students" :active="request()->is('students')">Students</x-layout.nav-link>
|
||||||
<x-layout.nav-link href="/entries" :actve="request()->is('entries')">Entries</x-layout.nav-link>
|
<x-layout.nav-link href="/entries" :active="request()->is('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="/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>--}}
|
{{-- <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>--}}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
<x-layout.page-section>
|
<x-layout.page-section>
|
||||||
<x-slot:section_name>Entry Listing</x-slot:section_name>
|
<x-slot:section_name>Entry Listing</x-slot:section_name>
|
||||||
|
<x-slot:section_description>You have {{ $entries->count() }} entries</x-slot:section_description>
|
||||||
<div class="px-4">
|
<div class="px-4">
|
||||||
<x-table.table>
|
<x-table.table>
|
||||||
<thead>
|
<thead>
|
||||||
|
|
@ -55,19 +56,16 @@
|
||||||
<x-table.td first>{{ $entry->student->full_name(true) }}</x-table.td>
|
<x-table.td first>{{ $entry->student->full_name(true) }}</x-table.td>
|
||||||
<x-table.td>{{ $entry->student->grade }}</x-table.td>
|
<x-table.td>{{ $entry->student->grade }}</x-table.td>
|
||||||
<x-table.td>{{ $entry->audition->name }}</x-table.td>
|
<x-table.td>{{ $entry->audition->name }}</x-table.td>
|
||||||
{{-- <x-table.td for_button>--}}
|
<x-table.td for_button>
|
||||||
{{-- <x-table.button href="/students/{{ $student->id }}/edit">Edit</x-table.button>--}}
|
<form method="POST" action="/entries/{{ $entry->id }}" class="inline">
|
||||||
{{-- |--}}
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
<x-table.button
|
||||||
|
onclick="return confirm('Please confirm you would like to delete the {{ $entry->audition->name }} entry for {{ $entry->student->full_name() }}');"
|
||||||
|
>Delete</x-table.button>
|
||||||
|
</form>
|
||||||
|
|
||||||
{{-- <form method="POST" action="/students/{{ $student->id }}" class="inline">--}}
|
</x-table.td>
|
||||||
{{-- @csrf--}}
|
|
||||||
{{-- @method('DELETE')--}}
|
|
||||||
{{-- <x-table.button--}}
|
|
||||||
{{-- onclick="return confirm('Please confirm you would like to delete the student {{ $student->full_name() }}');"--}}
|
|
||||||
{{-- >Delete</x-table.button>--}}
|
|
||||||
{{-- </form>--}}
|
|
||||||
|
|
||||||
{{-- </x-table.td>--}}
|
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</x-table.body>
|
</x-table.body>
|
||||||
|
|
|
||||||
|
|
@ -42,17 +42,17 @@
|
||||||
<x-table.td>{{ $student->grade }}</x-table.td>
|
<x-table.td>{{ $student->grade }}</x-table.td>
|
||||||
<x-table.td>{{ $student->entries->count() }}</x-table.td>
|
<x-table.td>{{ $student->entries->count() }}</x-table.td>
|
||||||
<x-table.td for_button>
|
<x-table.td for_button>
|
||||||
|
@can('delete', $student)
|
||||||
|
<form method="POST" action="/students/{{ $student->id }}" class="inline">
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
<x-table.button
|
||||||
|
onclick="return confirm('Please confirm you would like to delete the student {{ $student->full_name() }}');"
|
||||||
|
>Delete</x-table.button>
|
||||||
|
</form>
|
||||||
|
|
|
||||||
|
@endcan
|
||||||
<x-table.button href="/students/{{ $student->id }}/edit">Edit</x-table.button>
|
<x-table.button href="/students/{{ $student->id }}/edit">Edit</x-table.button>
|
||||||
|
|
|
||||||
|
|
||||||
<form method="POST" action="/students/{{ $student->id }}" class="inline">
|
|
||||||
@csrf
|
|
||||||
@method('DELETE')
|
|
||||||
<x-table.button
|
|
||||||
onclick="return confirm('Please confirm you would like to delete the student {{ $student->full_name() }}');"
|
|
||||||
>Delete</x-table.button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</x-table.td>
|
</x-table.td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,7 @@ Route::middleware(['auth','verified'])->group(function () {
|
||||||
Route::middleware(['auth','verified'])->controller(EntryController::class)->group(function() {
|
Route::middleware(['auth','verified'])->controller(EntryController::class)->group(function() {
|
||||||
Route::get('/entries','index');
|
Route::get('/entries','index');
|
||||||
Route::get('/entries/create','create');
|
Route::get('/entries/create','create');
|
||||||
Route::get('/entries/{entry}', 'show');
|
|
||||||
Route::post('/entries', 'store');
|
Route::post('/entries', 'store');
|
||||||
Route::get('/entries/{entry}/edit', 'edit');
|
|
||||||
Route::patch('/entries/{entry}', 'update');
|
|
||||||
Route::delete('/entries/{entry}', 'destroy');
|
Route::delete('/entries/{entry}', 'destroy');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue