81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use App\Http\Requests\SubjectPostRequest;
|
||
|
use App\Models\Subject;
|
||
|
use Illuminate\Http\RedirectResponse;
|
||
|
use Illuminate\Http\Request;
|
||
|
use Illuminate\View\View;
|
||
|
|
||
|
class SubjectController extends Controller
|
||
|
{
|
||
|
/**
|
||
|
* Display a listing of the resource.
|
||
|
*/
|
||
|
public function index(): View
|
||
|
{
|
||
|
return view('subjects.index', [
|
||
|
"subjects" => Subject::filter()->paginate(10)->withQueryString(),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the form for creating a new resource.
|
||
|
*/
|
||
|
public function create(): View
|
||
|
{
|
||
|
return view('subjects.create');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Store a newly created resource in storage.
|
||
|
*/
|
||
|
public function store(SubjectPostRequest $request): RedirectResponse
|
||
|
{
|
||
|
$subject = Subject::create($request->validated());
|
||
|
|
||
|
return redirect()->route('subjects.show', $subject);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Display the specified resource.
|
||
|
*/
|
||
|
public function show(Subject $subject): View
|
||
|
{
|
||
|
return view('subjects.show', [
|
||
|
"subject" => $subject
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the form for editing the specified resource.
|
||
|
*/
|
||
|
public function edit(Subject $subject): View
|
||
|
{
|
||
|
return view('subjects.edit', [
|
||
|
'subject' => $subject,
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Update the specified resource in storage.
|
||
|
*/
|
||
|
public function update(SubjectPostRequest $request, Subject $subject): RedirectResponse
|
||
|
{
|
||
|
$subject->update($request->validated());
|
||
|
|
||
|
return redirect()->route('subjects.show', $subject);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Remove the specified resource from storage.
|
||
|
*/
|
||
|
public function destroy(Subject $subject): RedirectResponse
|
||
|
{
|
||
|
$subject->delete();
|
||
|
|
||
|
return redirect()->route('subjects.index');
|
||
|
}
|
||
|
}
|