Skip to content

Commit

Permalink
Implement subject matter create, and showing list of subject matter f…
Browse files Browse the repository at this point in the history
…or classroom
  • Loading branch information
danivideda committed Dec 2, 2020
1 parent a8927d1 commit d163860
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 35 deletions.
16 changes: 1 addition & 15 deletions app/Http/Controllers/ClassroomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Models\Classroom;
use App\Models\SubjectMatter;
use Illuminate\Support\Str;
use Illuminate\Http\Request;

Expand All @@ -25,19 +26,4 @@ public function store(Request $request) {
return redirect()->route('teacher.dashboard');
}

public function indexSubjectMatter(Classroom $classroom) {
return view('teacher.course.subjectmatter', [
'classroom' => $classroom
]);
}

public function showSubjectMatter(Classroom $classroom) {
return view('teacher.course.subjectmatter', [
'classroom' => $classroom
]);
}

public function createSubjectMatter(Classroom $classroom) {
return view('teacher.class.createsubjectmatter');
}
}
49 changes: 49 additions & 0 deletions app/Http/Controllers/SubjectMatterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Classroom;
use App\Models\SubjectMatter;

class SubjectMatterController extends Controller
{
public function classroom() {
return $this->belongsTo(Classroom::class);
}

public function indexSubjectMatter(Classroom $classroom) {
$subjects = SubjectMatter::where('classroom_id', $classroom->id)->get();

return view('teacher.course.subjectmatter', [
'classroom' => $classroom,
'subjects' => $subjects
]);
}

public function showSubjectMatter(Classroom $classroom, SubjectMatter $subject) {
return "a single subjectmatter: {$subject->title}";
}

public function createSubjectMatter(Classroom $classroom) {
return view('teacher.class.createsubjectmatter', [
'classroom' => $classroom
]);
}

public function storeSubjectMatter(Classroom $classroom, Request $request) {
$this->validate($request, [
'title' => 'required|max:255',
'link' => 'url',
'content' => 'required'
]);

$classroom->subjectMatters()->create([
'title' => $request->title,
'link' => $request->link,
'content' => $request->content
]);

return redirect()->route('subjectmatter', $classroom->id);
}
}
6 changes: 1 addition & 5 deletions app/Http/Controllers/TeacherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
class TeacherController extends Controller
{
public function index() {
$classrooms = Classroom::get();
$classrooms = Classroom::where('teacher_id', auth('teacher')->user()->id)->get();

return view('teacher.home.dashboard', [
'classrooms' => $classrooms
]);
}

public function createClassroom(Request $request) {

}
}
8 changes: 8 additions & 0 deletions app/Models/SubjectMatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ class SubjectMatter extends Model
'url',
'content'
];

public function classroom() {
return $this->belongsTo(Classroom::class);
}

public function path() {
return "/teacher/classroom/{$this->classroom->id}/subject-matter/{$this->id}";
}
}
4 changes: 2 additions & 2 deletions resources/views/teacher/class/createsubjectmatter.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@section('nav')
<div class="text-center my-2 border-r-2 border-blue-500">
<button class="py-1 px-9 bg-white text-black rounded">
<a href="#" class="text-sm">Subject Matter</a>
<a href="{{ route('subjectmatter', $classroom->id) }}" class="text-sm">Subject Matter</a>
</button>
</div>
<div class="text-center my-2">
Expand All @@ -25,7 +25,7 @@
</div>
<div class="container">
<div class="flex flex-wrap flex-col md:flex-row items-center my-8 pl-12 mx-auto rounded-lg">
<form action="" method="POST">
<form action="{{ route('subjectmatter.create', $classroom->id) }}" method="POST">
@csrf
<div>
<label for="title" class="tracking-wide text-gray text-base font-bold pb-4">Title :</label>
Expand Down
14 changes: 8 additions & 6 deletions resources/views/teacher/course/subjectmatter.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</div>
<div class="container w-full">
<a href="#">
<a href="{{ route('subjectmatter.create', $classroom->id) }}">
<div class="bg-white w-4/12 mx-auto my-6 rounded flex bg-gray-200 hover:bg-gray-300">
<h1 class="text-black text-base w-10/12 px-4 py-4">Create New Subject Matter</h1>
<h1 class="text-black text-base italic font-extrabold w-2/12 px-4 py-4">+</h1>
Expand All @@ -42,11 +42,13 @@
<h1>Subject Matter :</h1>
</div>

<a href="#">
<div class="bg-white w-9/12 mx-auto px-4 py-4 my-6 rounded border-2 hover:border-gray-600">
<h1 class="text-black text-base italic">Test</h1>
</div>
</a>
@foreach ($subjects as $subject)
<a href="{{ $subject->path() }}">
<div class="bg-white w-9/12 mx-auto px-4 py-4 my-6 rounded border-2 hover:border-gray-600">
<h1 class="text-black text-base italic">{{ $subject->title }}</h1>
</div>
</a>
@endforeach
</div>
</div>
@endsection
6 changes: 3 additions & 3 deletions resources/views/teacher/home/dashboard.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@extends('layouts.teacherhome')

@section('maincontent')
<div class="container px-5">
<div class="mb-12 text-black text-4xl font-bold">
<div class="container">
<div class="mb-12 ml-12 text-black text-4xl font-bold">
<h1 class="">My Class</h1>
</div>
<div class="container w-full">
Expand All @@ -23,7 +23,7 @@
</a>
@endforeach
@else
<p>You don't have any classroom yet</p>
<p class="ml-12">You don't have any classroom yet</p>
@endif
</div>
</div>
Expand Down
9 changes: 5 additions & 4 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Controllers\ClassroomController;
use App\Http\Controllers\TeacherController;
use App\Http\Controllers\StudentController;
use App\Http\Controllers\SubjectMatterController;
use Illuminate\Support\Facades\Route;

/*
Expand Down Expand Up @@ -50,10 +51,10 @@
Route::get('/teacher/classroom/create', [ClassroomController::class, 'showCreateClassroom'])->name('classroom.create');
Route::post('/teacher/classroom/create', [ClassroomController::class, 'store']);

Route::get('/teacher/classroom/{classroom}/subject-matter', [ClassroomController::class, 'indexSubjectMatter'])->name('classroom.subjectmatter');
Route::get('/teacher/classroom/{classroom}/subject-matter/create', [ClassroomController::class, 'createSubjectMatter']);
Route::get('/teacher/classroom/{classroom}/subject-matter/{subject}', [ClassroomController::class, 'showSubjectMatter']);
// Route::post('/teacher/classroom/{classroom}/subject-matter/create', [ClassroomController::class, 'storeSubjectMatter']);
Route::get('/teacher/classroom/{classroom}/subject-matter', [SubjectMatterController::class, 'indexSubjectMatter'])->name('subjectmatter');
Route::get('/teacher/classroom/{classroom}/subject-matter/create', [SubjectMatterController::class, 'createSubjectMatter'])->name('subjectmatter.create');
Route::post('/teacher/classroom/{classroom}/subject-matter/create', [SubjectMatterController::class, 'storeSubjectMatter']);
Route::get('/teacher/classroom/{classroom}/subject-matter/{subject}', [SubjectMatterController::class, 'showSubjectMatter']);

Route::get('/teacher/assignment', function () {
return view('teacher.course.assignment');
Expand Down

0 comments on commit d163860

Please sign in to comment.