Skip to content

teacher student actions#4

Open
minhquanghapo wants to merge 1 commit intoadminactionfrom
TeacherStudentAction
Open

teacher student actions#4
minhquanghapo wants to merge 1 commit intoadminactionfrom
TeacherStudentAction

Conversation

@minhquanghapo
Copy link
Owner

Create Actions for Student and Teacher.

use App\Http\Requests\RequestTeacher;
use App\Model\Classes;
use App\Model\Teacher;
use function bcrypt;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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'],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 vẫn dùng tên Classes à e ?

public function registerClass($id) {
$student = Auth::guard('student')->user();
$classes = $student->classes;
foreach($classes as $clss)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 sao ko dùng as $class ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 score mặc định là -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');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 redirect theo route nhé

//
public function deleteClass($id) {
$student = Auth::guard('student')->user();
$class_id = Classes::where('id','=',$id)->first();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 Request này validate chưa e ?

}

public function classes() {
$data = Classes::latest()->paginate(5);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 nên đặt tên $classes thay vì $data

}

public function listClass() {
$teacher_id = Auth::guard('teacher')->user()->id;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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) )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 cái này default rồi e

'password', 'remember_token',
'remember_token', 'password',
];
public $primaryKey = 'id';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 cái này default rồi e

<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>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 câu tiếng anh này có gì đấy sai sai :)))

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 dùng {{ route('route_name') thay vì url

@foreach($data as $row)
<tr>

<td>{!!$row->id!!}</td>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 thêm space đi e. đoạn này ko cần dùn {!! chỉ cần dùng {{.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{{ $row->id }}

</tr>
</thead>
<tbody>
{{$i=0}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 sao lại có đoạn này nhỉ ?


<td>{!!$row->id!!}</td>
<td>
{!!App\Model\Subject::find($row->subject_id)->name!!}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 chuyển hết sang route

@@ -0,0 +1,21 @@
@extends('teacher.layouts.master')
@section('content')
<form action="{{url('teacher/class/update-score/'.$student->id.'/'.$classes_id)}}" method="POST">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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']);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhquang97 delete dùng method delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments