Conversation
| use App\Http\Requests\RequestTeacher; | ||
| use App\Model\Classes; | ||
| use App\Model\Teacher; | ||
| use function bcrypt; |
There was a problem hiding this comment.
@minhquang97 hàm này sao phải use e nhỉ ? nó là helper method mà.
| $teacher = Teacher::create($request->all()); | ||
| $data = $request->all(); | ||
| $teacher = new Teacher(); | ||
| $data->id => $data['id'] |
There was a problem hiding this comment.
@minhquang97 sao lại là $data->id nhỉ ? phải là $teacher->key = $request->key ?
| $data->name => $data['name'], | ||
| $data->birthday => $data['birthday'], | ||
| $data->password => bcrypt($data['password']), | ||
| 'email' => $data['email'], |
There was a problem hiding this comment.
@minhquang97 phần này có nhầm lẫn gì ko e ?
| 'email' => $data['email'], | ||
| $teacher->save(); | ||
|
|
||
| return redirect('admin/teacher/list-teacher')->with('success','Create Teacher Successfully'); |
There was a problem hiding this comment.
@minhquang97 ko rediect theo url nhé dùng redirect()->route('route_name')
| ->with('success','Student updated successfully'); | ||
| // | ||
| public function classes() { | ||
| $data = Classes::latest()->paginate(5); |
| public function registerClass($id) { | ||
| $student = Auth::guard('student')->user(); | ||
| $classes = $student->classes; | ||
| foreach($classes as $clss) |
There was a problem hiding this comment.
@minhquang97 đừng viết kiểu tab thế này e ơi. viết {} đầy đủ đi.
| $classes = $student->classes; | ||
| foreach($classes as $clss) | ||
| if($clss->id == $id) return back()->with('danger','Class already registered'); | ||
| $student->classes()->attach($id, ['score' => -1]); |
| foreach($classes as $clss) | ||
| if($clss->id == $id) return back()->with('danger','Class already registered'); | ||
| $student->classes()->attach($id, ['score' => -1]); | ||
| return redirect()->action('Student\StudentController@listClass')->with('success', 'Register Class Successfully'); |
| // | ||
| public function deleteClass($id) { | ||
| $student = Auth::guard('student')->user(); | ||
| $class_id = Classes::where('id','=',$id)->first(); |
There was a problem hiding this comment.
@minhquang97 khi tìm theo id có thể dùng find hoặc findOrFail. Sự khác nhau giữa 2 hàm này e cũng nên tìm hiểu
There was a problem hiding this comment.
@minhquang97 đặt tên biến chỗ này cũng có vấn đề ?
| public function deleteClass($id) { | ||
| $student = Auth::guard('student')->user(); | ||
| $class_id = Classes::where('id','=',$id)->first(); | ||
| $student->classes()->detach($class_id); |
There was a problem hiding this comment.
@minhquang97 khi detach thì chỉ cần truyền thẳng cái $id từ browser nên vào hàm này là đc ?
| return view('teacher.auth.login'); | ||
| } | ||
|
|
||
| public function authenticate(Request $request) |
There was a problem hiding this comment.
@minhquang97 Request này validate chưa e ?
| } | ||
|
|
||
| public function classes() { | ||
| $data = Classes::latest()->paginate(5); |
There was a problem hiding this comment.
@minhquang97 nên đặt tên $classes thay vì $data
| } | ||
|
|
||
| public function listClass() { | ||
| $teacher_id = Auth::guard('teacher')->user()->id; |
There was a problem hiding this comment.
@minhquang97 đặt tên biến theo PSR2 sử dụng camelCase $teacherId
| <div class="col-md-4 col-md-offset-2"> | ||
| <h3>Thông tin giáo viên</h3> | ||
|
|
||
| @if (isset(Auth::guard('teacher')->user()->name) ) |
There was a problem hiding this comment.
chú check lại xem, thằng teacher này nó phải pass cái middleware thì mới vào được trang này mà. Nên có lẽ không cần isset để kiểm tra đâu
| return $this->belongsToMany(Student::class,'student_class','class_id','student_id')->withPivot('score'); | ||
| } | ||
|
|
||
| public $primaryKey = 'id'; |
| 'password', 'remember_token', | ||
| 'remember_token', 'password', | ||
| ]; | ||
| public $primaryKey = 'id'; |
| <td> | ||
| <a href="{!!url('admin/class/edit-class/'.$row->id)!!}" title="Sửa" class="btn btn-info"><span >Edit</span> </a> | ||
| <a href="{!!url('admin/class/delete-class/'.$row->id)!!}" class="btn btn-danger"><span>Remove</span> </a> | ||
| <a href="{!!url('admin/class/delete-class/'.$row->id)!!}" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this item?');"><span>Remove</span> </a> |
There was a problem hiding this comment.
@minhquang97 câu tiếng anh này có gì đấy sai sai :)))
There was a problem hiding this comment.
@minhquang97 khi xóa theo kiểu này là e đang dùng method GET à ?
| @@ -63,14 +63,13 @@ | |||
| <td>{!!$row->semester!!}</td> | |||
| <td> | |||
| <a href="{!!url('admin/class/edit-class/'.$row->id)!!}" title="Sửa" class="btn btn-info"><span >Edit</span> </a> | |||
There was a problem hiding this comment.
@minhquang97 dùng {{ route('route_name') thay vì url
| @foreach($data as $row) | ||
| <tr> | ||
|
|
||
| <td>{!!$row->id!!}</td> |
There was a problem hiding this comment.
@minhquang97 thêm space đi e. đoạn này ko cần dùn {!! chỉ cần dùng {{.
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {{$i=0}} |
|
|
||
| <td>{!!$row->id!!}</td> | ||
| <td> | ||
| {!!App\Model\Subject::find($row->subject_id)->name!!} |
There was a problem hiding this comment.
@minhquang97 sao lại viết query ở view thế này e ? viết kiểu này thành n + 1 query rồi. Cái này a nói hôm trước rồi mà. Mình dùng with https://laravel.com/docs/5.5/eloquent-relationships#constraining-eager-loads
| <a href="{{url('student/home')}}">Học sinh</a> | ||
| <a href="{{url('student/list-class')}}">Lớp học đã đăng kí</a> | ||
| <a href="{{url('student/register-class')}}">Đăng kí lớp học</a> | ||
| <a href="{{url('student/class/list-class')}}">Lớp học đã đăng kí</a> |
| @@ -0,0 +1,21 @@ | |||
| @extends('teacher.layouts.master') | |||
| @section('content') | |||
| <form action="{{url('teacher/class/update-score/'.$student->id.'/'.$classes_id)}}" method="POST"> | |||
There was a problem hiding this comment.
@minhquang97 chuyển hết tất cả chỗ dùng url sang route
| Route::get('class', ['as' => 'teacher-class', 'uses' => 'TeacherController@classes']); | ||
| Route::get('class/list-class', ['as' => 'teacher-list-class', 'uses' => 'TeacherController@listClass']); | ||
| Route::get('class/register-class/{id}', ['as' => 'teacher-register-class', 'uses' => 'TeacherController@registerClass']); | ||
| Route::get('class/delete-class/{id}', ['as' => 'teacher-delete-class', 'uses' => 'TeacherController@deleteClass']); |
Create Actions for Student and Teacher.