Skip to content
Snippets Groups Projects
Commit 651bfa23 authored by LIENHARDT QUENTIN's avatar LIENHARDT QUENTIN :snake:
Browse files

Added subject controller + page create show

parent eeee4db3
Branches
No related merge requests found
<?php
namespace App\Http\Controllers;
use App\Http\Requests\SubjectRequest;
use App\Models\Subject;
use Illuminate\Http\Request;
class SubjectController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$subjects = Subject::orderBy('name', 'asc')->get();
return view('subject.index', ['subjects' => $subjects]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('subject.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(SubjectRequest $request)
{
$data = $request->validated();
$subject = new Subject();
$subject->fill($data);
$subject->save();
return redirect()->route('subject.show', $subject);
}
/**
* Display the specified resource.
*
* @param \App\Models\Subject $subject
* @return \Illuminate\Http\Response
*/
public function show(Subject $subject)
{
return view('subject.show', ['subject' => $subject]);
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Subject $subject
* @return \Illuminate\Http\Response
*/
public function edit(Subject $subject)
{
return;
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Subject $subject
* @return \Illuminate\Http\Response
*/
public function update(SubjectRequest $request, Subject $subject)
{
return;
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Subject $subject
* @return \Illuminate\Http\Response
*/
public function destroy(Subject $subject)
{
return;
}
}
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SubjectRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
];
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Subject extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = ['name'];
}
......@@ -1181,6 +1181,9 @@ select {
.block {
display: block;
}
.inline-block {
display: inline-block;
}
.flex {
display: flex;
}
......@@ -1510,6 +1513,14 @@ select {
--tw-bg-opacity: 1;
background-color: rgba(229, 231, 235, var(--tw-bg-opacity));
}
.bg-green-500 {
--tw-bg-opacity: 1;
background-color: rgba(16, 185, 129, var(--tw-bg-opacity));
}
.bg-gray-300 {
--tw-bg-opacity: 1;
background-color: rgba(209, 213, 219, var(--tw-bg-opacity));
}
.bg-opacity-25 {
--tw-bg-opacity: 0.25;
}
......@@ -1532,6 +1543,9 @@ select {
.p-6 {
padding: 1.5rem;
}
.p-1 {
padding: 0.25rem;
}
.px-4 {
padding-left: 1rem;
padding-right: 1rem;
......@@ -1755,6 +1769,10 @@ select {
--tw-text-opacity: 1;
color: rgba(209, 213, 219, var(--tw-text-opacity));
}
.text-blue-500 {
--tw-text-opacity: 1;
color: rgba(59, 130, 246, var(--tw-text-opacity));
}
.underline {
text-decoration: underline;
}
......@@ -1894,6 +1912,9 @@ select {
--tw-text-opacity: 1;
color: rgba(17, 24, 39, var(--tw-text-opacity));
}
.hover\:underline:hover {
text-decoration: underline;
}
.focus\:z-10:focus {
z-index: 10;
}
......
......@@ -16,6 +16,11 @@
{{ __('Dashboard') }}
</x-jet-nav-link>
</div>
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
<x-jet-nav-link href="{{ route('subject.index') }}" :active="request()->routeIs('subject.*')">
{{ __('Subjects') }}
</x-jet-nav-link>
</div>
</div>
<div class="hidden sm:flex sm:items-center sm:ml-6">
......
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ 'Create a new subject' }}
</h2>
</x-slot>
<form action="{{ route('subject.store') }}" method="POST">
@csrf
<input type="text" name="name" placeholder="Name" value="{{ old('name') }}">
<button type="submit">Create</button>
</form>
@if ($errors->any())
<br>
<h3>Errors</h3>
@foreach ($errors->all() as $item)
<li>{{ $item }}</li>
@endforeach
@endif
</x-app-layout>
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ 'All subjects' }}
</h2>
</x-slot>
<a href="{{ route('subject.create') }}" class="bg-green-500 text-white p-1 inline-block">New subject</a>
<br>
@foreach ($subjects as $subject)
<a href="{{ route('subject.show', $subject) }}" class="text-blue-500 hover:underline">{{ $subject->created_at }} {{ $subject->name }}</a>
<br>
@endforeach
</x-app-layout>
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ 'Subject "' . $subject->name . '"'}}
</h2>
</x-slot>
<a href="{{ url('subject') }}" class="bg-gray-300 p-1 inline-block">Back</a>
<p>published : {{ date('d-m-Y H:i', strtotime($subject->created_at)) }}</p>
</x-app-layout>
<?php
use App\Http\Controllers\SubjectController;
use Illuminate\Support\Facades\Route;
/*
......@@ -13,10 +14,14 @@ use Illuminate\Support\Facades\Route;
|
*/
Route::get('/', function () {
Route::get('/', function ()
{
return view('welcome');
});
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function ()
{
return view('dashboard');
})->name('dashboard');
Route::resource('/subject', SubjectController::class);
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment