Skip to content

Commit

Permalink
Implement join class, show list of class on student dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
danivideda committed Dec 3, 2020
1 parent 5bed973 commit 372f7f4
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 24 deletions.
23 changes: 22 additions & 1 deletion app/Http/Controllers/StudentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@

namespace App\Http\Controllers;

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

class StudentController extends Controller
{
public function index() {
return view('student.home.dashboard');
$classrooms = auth('student')->user()->classrooms;

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

public function join() {
return view('student.home.joinclass');
}

public function link(Request $request) {
$this->validate($request, [
'class_code' => 'required|exists:classrooms,code'
]);

$classroom = Classroom::where('code', $request->class_code)->first();

auth('student')->user()->classrooms()->attach($classroom);

return redirect()->route('student.dashboard');
}
}
2 changes: 1 addition & 1 deletion app/Models/Classroom.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Classroom extends Model
];

public function students() {
return $this->hasMany(Student::class);
return $this->belongsToMany(Student::class);
}

public function subjectMatters() {
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Student.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ class Student extends Authenticatable
'email_verified_at' => 'datetime',
];

public function classrooms() {
return $this->belongsToMany(Classroom::class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateClassroomStudentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('classroom_student', function (Blueprint $table) {
$table->foreignId('classroom_id');
$table->foreignId('student_id');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('classroom_student');
}
}
4 changes: 2 additions & 2 deletions resources/views/layouts/studenthome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</div>
<div class="text-center mb-8">
<button class="py-1 px-9 bg-blue-500 text-white rounded hover:bg-blue-700">
<a href="#">Join a class</a>
<a href="{{ route('student.classroom.join') }}">Join a class</a>
</button>
</div>
<div class="text-center border-r-2 border-blue-500">
<button class="py-1 px-9 bg-white text-black rounded">
<a href="#" class="text-sm">My Class</a>
<a href="{{ route('student.dashboard') }}" class="text-sm">My Class</a>
</button>
</div>
</div>
Expand Down
30 changes: 18 additions & 12 deletions resources/views/student/home/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
<h1 class="pl-12">My Class</h1>
</div>
<div class="container w-full">
<a href="#">
<div class="flex flex-wrap flex-col md:flex-row items-center bg-white my-8 w-9/12 mx-auto rounded-lg border-2 hover:border-gray-600">
<div class="flex flex-col xl:w-2/5 overflow-y-hidden lg:items-start pl-4">
<h1 class="text-xl text-black text-left mb-4">Pemrograman</h1>
<h1 class="text-sm text-blacktext-left">Melati</h1>
<p class="text-sm text-left">SMAN 8 Jogja</p>
</div>
<div class="xl:w-3/5 overflow-y-hidden rounded-lg">
<img class="w-full rounded-lg" src="{{asset('img/logo.PNG')}}">
</div>
</div>
</a>
@if ($classrooms->count())
@foreach ($classrooms as $classroom)
<a href="#">
<div class="flex flex-wrap flex-col md:flex-row items-center bg-white my-8 w-9/12 mx-auto rounded-lg border-2 hover:border-gray-600">
<div class="flex flex-col xl:w-2/5 overflow-y-hidden lg:items-start pl-4">
<h1 class="text-xl text-black text-left mb-4">{{ $classroom->class_name }}</h1>
<h1 class="text-sm text-blacktext-left">{{ $classroom->teacher->name }}</h1>
<p class="text-sm text-left">{{ $classroom->teacher->school_name }}</p>
</div>
<div class="xl:w-3/5 overflow-y-hidden rounded-lg">
<img class="w-full rounded-lg" src="{{asset('img/logo.PNG')}}">
</div>
</div>
</a>
@endforeach
@else
<p class="ml-12">You didn't join any classroom yet</p>
@endif
</div>
</div>
@endsection
10 changes: 5 additions & 5 deletions resources/views/student/home/joinclass.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
</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('student.classroom.join') }}" method="POST">
@csrf
<div>
<label for="classname" class="tracking-wide text-gray text-base font-bold pb-4">Class Name :</label>
<label for="class_code" class="tracking-wide text-gray text-base font-bold pb-4">Class Code :</label>
</div>
<div class="mb-4">
<input type="text" name="classname" id="classname" placeholder="Search your class here"
class="bg-gray-100 border-2 border-blue-400 mt-4 py-4 px-4 rounded-lg @error('classname') border-red-500 @enderror" value="{{ old('classname') }}" style="width: 32rem">
<input type="text" name="class_code" id="class_code" placeholder="Search your class using code here..."
class="bg-gray-100 border-2 border-blue-400 mt-4 py-4 px-4 rounded-lg @error('class_code') border-red-500 @enderror" value="{{ old('class_code') }}" style="width: 32rem">

@error('classname')
@error('class_code')
<div class="text-red-500 mt-2 text-base">
{{ $message }}
</div>
Expand Down
10 changes: 7 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@

Route::middleware('auth.student')->group(function () {
Route::get('/student/dashboard', [StudentController::class, 'index'])->name('student.dashboard');
Route::get('/student/join', function () {
return view('student.home.joinclass');
});

Route::get('/student/classroom/join', [StudentController::class, 'join'])->name('student.classroom.join');
Route::post('/student/classroom/join', [StudentController::class, 'link']);

Route::get('/student/classroom/{classroom}/subject-matter', [SubjectMatterController::class, 'index'])->name('student.subjectmatter');
Route::get('/student/classroom/{classroom}/subject-matter/{subject}', [SubjectMatterController::class, 'show'])->name('student.subjectmatter.show');

Route::get('/student/subjectmatter', function () {
return view('student.course.subjectmatter');
});
Expand Down

0 comments on commit 372f7f4

Please sign in to comment.