Skip to content

Commit 78ec0d0

Browse files
committed
add table teacher and student
1 parent b3d0472 commit 78ec0d0

File tree

8 files changed

+284
-2
lines changed

8 files changed

+284
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Grade;
6+
use Illuminate\Http\Request;
7+
8+
class StudentDashboardController extends Controller
9+
{
10+
public function index()
11+
{
12+
$studentId = auth()->id();
13+
$grades = Grade::where('student_id', $studentId)->with('course')->get();
14+
15+
// برگرداندن نمای 'student.dashboard' با متغیر 'grades'
16+
return view('student.dashboard', compact('grades'));
17+
}
18+
19+
public function storeObjection(Request $request)
20+
{
21+
Objection::create([
22+
'student_id' => auth()->id(),
23+
'course_id' => $request->course_id,
24+
'objection_text' => $request->objection_text,
25+
]);
26+
27+
return redirect()->back()->with('success', 'Objection submitted successfully');
28+
}
29+
}

app/Models/Course.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Course extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $fillable = ['course_name', 'teacher_id'];
13+
14+
public function teacher()
15+
{
16+
return $this->belongsTo(Teacher::class);
17+
}
18+
19+
public function grades()
20+
{
21+
return $this->hasMany(Grade::class);
22+
}
23+
}
24+

app/Models/Grade.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Grade extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $fillable = ['student_id', 'course_id', 'grade'];
13+
14+
public function student()
15+
{
16+
return $this->belongsTo(Student::class);
17+
}
18+
19+
public function course()
20+
{
21+
return $this->belongsTo(Course::class);
22+
}
23+
}

app/Models/Objection.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Objection extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $fillable = ['student_id', 'course_id', 'objection_text'];
13+
14+
public function student()
15+
{
16+
return $this->belongsTo(Student::class);
17+
}
18+
19+
public function course()
20+
{
21+
return $this->belongsTo(Course::class);
22+
}
23+
}

app/Models/Student.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Student extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $fillable = ['student_id', 'name'];
13+
14+
public function grades()
15+
{
16+
return $this->hasMany(Grade::class);
17+
}
18+
19+
public function objections()
20+
{
21+
return $this->hasMany(Objection::class);
22+
}
23+
}

app/Models/Teacher.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Teacher extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $fillable = ['teacher_id', 'name'];
13+
14+
public function courses()
15+
{
16+
return $this->hasMany(Course::class);
17+
}
18+
}

resources/views/dashboard.blade.php

+80-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,83 @@
1414
</div>
1515
</div>
1616
</div>
17-
</x-app-layout>
18-
17+
18+
<!-- جدول دروس و نمرات -->
19+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 mt-8">
20+
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg flex justify-end">
21+
<div class="p-6 text-gray-900">
22+
<table class="min-w-full divide-y divide-gray-200 mt-4">
23+
<thead>
24+
<tr>
25+
<th
26+
class="px-6 py-3 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
27+
اعتراض</th>
28+
<th
29+
class="px-6 py-3 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
30+
نمره</th>
31+
<th
32+
class="px-6 py-3 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
33+
درس</th>
34+
35+
</tr>
36+
</thead>
37+
<tbody>
38+
@php
39+
$courses = ['صدا در چند رسانه ای', 'کاربرد های وب', 'گرافیک متحرک', 'تجزیه تحلیل', 'هوش مصنوعی', 'تصویر برداری'];
40+
$grades = [18, 15, 16, 19, 12, 17];
41+
@endphp
42+
@foreach($courses as $index => $course)
43+
<tr class="bg-white divide-y divide-gray-200">
44+
<td class="px-6 py-4 whitespace-nowrap text-right">
45+
<button class="bg-blue-500 hover:bg-blue-700 text-black font-bold py-2 px-4 rounded"
46+
onclick="openObjectionModal('{{ $course }}')">ثبت اعتراض</button>
47+
</td>
48+
<td class="px-6 py-4 whitespace-nowrap text-right">
49+
<input type="text" value="{{ $grades[$index] }}" readonly
50+
class="border-none bg-transparent rounded-full text-gray-500">
51+
</td>
52+
<td class="px-6 py-4 whitespace-nowrap text-right">{{ $course }}</td>
53+
54+
55+
</tr>
56+
@endforeach
57+
</tbody>
58+
</table>
59+
</div>
60+
</div>
61+
</div>
62+
</div>
63+
64+
<!-- پاپ‌آپ اعتراض -->
65+
<div id="objectionModal" class="fixed z-10 inset-0 overflow-y-auto hidden flex justify-center items-center">
66+
<div class="fixed inset-0 transition-opacity">
67+
<div class="absolute inset-0 bg-gray-500 opacity-75"></div>
68+
</div>
69+
<div class="bg-white rounded-lg shadow-xl transform transition-all sm:max-w-lg w-full p-6">
70+
<h3 class="text-lg leading-6 font-medium text-gray-900 mb-4" id="modal-title">ثبت اعتراض</h3>
71+
<textarea id="objection_text" rows="4" class="form-input mt-2 block w-full"
72+
placeholder="اعتراض خود را وارد کنید..."></textarea>
73+
<div class="mt-4 flex justify-end space-x-2">
74+
<button onclick="submitObjection()"
75+
class="inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-green-500 text-base font-semibold text-green hover:bg-green-600 focus:outline-none sm:w-auto sm:text-sm">ثبت</button>
76+
<button onclick="closeObjectionModal()"
77+
class="inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none sm:w-auto sm:text-sm">لغو</button>
78+
</div>
79+
</div>
80+
</div>
81+
<script>
82+
function openObjectionModal(course) {
83+
document.getElementById("objectionModal").classList.remove("hidden");
84+
document.getElementById("modal-title").innerText = ` ثبت اعتراض برای ${course}`;
85+
}
86+
87+
function closeObjectionModal() {
88+
document.getElementById("objectionModal").classList.add("hidden");
89+
}
90+
91+
function submitObjection() {
92+
closeObjectionModal();
93+
alert("اعتراض شما با موفقیت ثبت شد");
94+
}
95+
</script>
96+
</x-app-layout>

resources/views/teacher/dashboard.blade.php

+64
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,69 @@
1414
</div>
1515
</div>
1616
</div>
17+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 mt-8">
18+
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
19+
<div class="p-6 text-gray-900">
20+
<!-- Dropdown برای انتخاب درس -->
21+
<div class="mb-4">
22+
<label for="course" class="block text-sm font-medium text-gray-700">انتخاب درس:</label>
23+
<select id="course"
24+
class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md">
25+
@php
26+
$courses = ['صدا در چند رسانه ای', 'کاربرد های وب', 'گرافیک متحرک', 'تجزیه تحلیل', 'هوش مصنوعی', 'تصویر برداری'];
27+
@endphp
28+
@foreach($courses as $course)
29+
<option>{{ $course }}</option>
30+
@endforeach
31+
</select>
32+
</div>
33+
34+
<!-- جدول ورود نمرات دانشجویان -->
35+
<table class="min-w-full divide-y divide-gray-200 mt-4">
36+
<thead>
37+
<tr>
38+
<th
39+
class="px-6 py-3 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
40+
نام دانشجو</th>
41+
<th
42+
class="px-6 py-3 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
43+
نمره</th>
44+
<th
45+
class="px-6 py-3 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
46+
ثبت نمره</th>
47+
</tr>
48+
</thead>
49+
<tbody>
50+
@php
51+
$students = ['علی حسینی', 'سارا محمدی', 'مریم نوری', 'احمد کریمی', 'زهرا رضایی'];
52+
@endphp
53+
@foreach($students as $student)
54+
<tr class="bg-white divide-y divide-gray-200">
55+
<td class="px-6 py-4 whitespace-nowrap text-right">{{ $student }}</td>
56+
<td class="px-6 py-4 whitespace-nowrap text-right">
57+
<!-- فیلد ورودی نمره -->
58+
<input type="text" class="border border-gray-300 rounded-md px-2 py-1"
59+
placeholder="نمره را وارد کنید">
60+
</td>
61+
<td class="px-6 py-4 whitespace-nowrap text-right">
62+
<!-- دکمه ثبت نمره -->
63+
<button class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"
64+
onclick="submitGrade()">ثبت نمره</button>
65+
</td>
66+
</tr>
67+
@endforeach
68+
</tbody>
69+
</table>
70+
</div>
71+
</div>
72+
</div>
73+
</div>
74+
75+
<script>
76+
function submitGrade() {
77+
alert('نمره با موفقیت ثبت شد');
78+
}
79+
</script>
1780
</x-app-layout>
1881

82+

0 commit comments

Comments
 (0)