Conversation
| // | ||
| public function show(){ | ||
| $employees = DB::table('employees')->orderBy('name')->paginate(10); | ||
| return view('index',['employees'=>$employees]); |
There was a problem hiding this comment.
nên dùng Eloquent String thay vì Query Builder https://laravel.com/docs/5.5/eloquent tuy QB có tốc độ truy vấn nhanh hơn nhưng khi câu query dài, phức tạp thì ES sẽ dễ hiểu hơn
There was a problem hiding this comment.
@TruongPhan16, @thiennguyen84 ngoài ra thì dùng Eloquent Engine thì dữ liệu trả về mới là các Model Object đã extend từ Eloquent, lúc đó mới sử dụng được các method định nghĩa trong model và các method hỗ trợ bởi Eloquent
| ], | ||
| [ | ||
| 'email.unique'=>'Email đã có người sử dụng', | ||
| ]); |
There was a problem hiding this comment.
nên tách ra file request riêng https://laravel.com/docs/5.5/validation#form-request-validation
There was a problem hiding this comment.
@TruongPhan16 e làm cái controller mới r nhé.@@
| $employee->name = $request->name; | ||
| $employee->address = $request->address; | ||
| $employee->birth_day = $request->birthday; | ||
| $employee->email = $request->email; |
There was a problem hiding this comment.
birth day e để kiểu date nên k nhập được kí tự
There was a problem hiding this comment.
tức là birthday là 1 từ thôi chứ k phải birth_day
| use Validator; | ||
| use File; | ||
|
|
||
| class EmployeeController extends Controller |
There was a problem hiding this comment.
nên dùng controller resource cho CRUD https://laravel.com/docs/5.5/controllers#resource-controllers
There was a problem hiding this comment.
@TruongPhan16 đang training nên cần giải thích thêm tại sao ?
| } | ||
|
|
||
| public function delete($id){ | ||
| $employee = Employee::find($id); |
There was a problem hiding this comment.
sử dụng findOrFail vì khi không tìm thấy sẽ trả về trang 404
| $searchs = Employee::where('name','like','%'.$name.'%')->orderBy('name')->paginate(10); | ||
| return view('search',['searchs'=>$searchs,'name'=>$name]); | ||
| } | ||
| } |
There was a problem hiding this comment.
function này có thể gộp chung vào index
There was a problem hiding this comment.
@TruongPhan16 tách như thế này có thể refactoring để search bằng ajax ?
There was a problem hiding this comment.
@chungth thế là e tách ra như này có phải gộp lại k a. :v
resources/views/add.blade.php
Outdated
| </div> | ||
| @endif | ||
| <div class="col-lg-6 col-lg-offset-3"> | ||
| <form action = "{{route('add')}}" method="POST" enctype="multipart/form-data"> |
There was a problem hiding this comment.
@TruongPhan16 thiếu space là sao a
There was a problem hiding this comment.
@thiennguyen84 tức là thiếu dấu cách ấy
resources/views/add.blade.php
Outdated
| </div> | ||
| <div class="form-group"> | ||
| <label for="email">Email:</label> | ||
| <input type="email" class="form-control" name= "email" value="@gmail.com" required=""> |
There was a problem hiding this comment.
value="@gmail.com" là như thế nào nhỉ?
There was a problem hiding this comment.
@TruongPhan16 e cho sẵn value là @gmail.com để chỉ cần nhập phần tên đầu thôi
There was a problem hiding this comment.
thế hotmail hay các mail khác thì sao?
There was a problem hiding this comment.
e đặt value vậy thôi chứ người ta có thể xóa value nhập hotmail khác mà a.:v
| </ul> | ||
| </div> | ||
| @endif | ||
| <div class="row"> |
There was a problem hiding this comment.
nên hiện error vào input tương ứng thay vì hiện tất cả
resources/views/edit.blade.php
Outdated
| {{ csrf_field() }} | ||
| <div class="col-lg-6"> | ||
| <div class="avata_name"> | ||
| Avata |
| @endif | ||
| <div class="row"> | ||
| <form action = "{{route('edit',$employee->id)}}" method="POST" enctype="multipart/form-data"> | ||
| {{ csrf_field() }} |
There was a problem hiding this comment.
sử dụng method PUT hoặc PATCH khi update cho đúng chuẩn RESTful
There was a problem hiding this comment.
@TruongPhan16 mà nếu đặt PUT PATH thì để form up ảnh riêng à anh
There was a problem hiding this comment.
{{ method_field('PUT') }}
thêm cái này vào anh ơi. Mà không phải tạo form up ảnh riêng đâu anh.
resources/views/index.blade.php
Outdated
| @foreach ($employees as $value) | ||
| <?php $dem++; ?> | ||
| <tr> | ||
| <td>{{$dem}}</td> |
There was a problem hiding this comment.
- Nên dùng biến tiếng anh thay vì tiếng việt
- Không cần đoạn
<?php $dem++; ?>cho$dem++ởtdđầu tiên là được - Blade template có hỗ trợ
@php @endphpthay cho thẻ đóng mởphp
resources/views/index.blade.php
Outdated
| <td>{{$dem}}</td> | ||
| <td>{{$value->name}}</td> | ||
| <td><img src="http://localhost:8000/img/{{$value->image}}" width="40" height="35px" alt=""></td> | ||
| <td>{{$value->email}}</td> |
There was a problem hiding this comment.
- Sử dụng
assethelper thay vì viết cả url ra như này https://laravel.com/docs/5.5/helpers#method-asset - Đừng style css inline
resources/views/index.blade.php
Outdated
| </tbody> | ||
| </table> | ||
| <div class="row">{{$employees->links()}}</div> | ||
| </div> |
There was a problem hiding this comment.
Như này thì phần phân trang sẽ không ra chính giữa đúng k nhỉ
There was a problem hiding this comment.
@TruongPhan16 Quy định là ra giữa a???
There was a problem hiding this comment.
@thiennguyen84 ra giữa cho dễ nhìn thôi
resources/views/search.blade.php
Outdated
| <td>{{$value->address}}</td> | ||
| <td><div class="edit"><a href="{{route('edit',$value->id)}}" class="btn btn-info"><span class="ti-pencil-alt"></span></a></div></td> | ||
| <td><form action="/task/{{ $value->id }}" method="POST"> | ||
| {{ csrf_field() }} |
There was a problem hiding this comment.
truyền route name vào action thay vì hard code
routes/web.php
Outdated
| Route::get('search',[ | ||
| 'as'=>'search', | ||
| 'uses'=>'EmployeeController@search' | ||
| ]); No newline at end of file |
There was a problem hiding this comment.
Tất cả route trên có thể thay bằng Route::resource cho ngắn gọn
There was a problem hiding this comment.
@TruongPhan16 thế là phải làm lại route à a.@@
There was a problem hiding this comment.
@thiennguyen84 cách của em ko sai nhưng @TruongPhan16 có giới thiệu cái Route::resource để sau em định nghĩa nó sẽ ngắn gọn và dễ hơn, em đọc trong laravel doc nhé
chungth
left a comment
There was a problem hiding this comment.
Các file trong folder
public/img là file được người dùng upload lên ?
Những file đó thuộc về dữ liệu của app nên cần ignore khỏi git repo
| @endif | ||
| <div class="row"> | ||
| <form action = "{{route('edit',$employee->id)}}" method="POST" enctype="multipart/form-data"> | ||
| {{ csrf_field() }} |
There was a problem hiding this comment.
{{ method_field('PUT') }}
thêm cái này vào anh ơi. Mà không phải tạo form up ảnh riêng đâu anh.
resources/views/header.blade.php
Outdated
| <div class="container"> | ||
| <div class="navbar-header"> | ||
| <img src="asset/images/hapo.jpg" class="hapo_img" alt=""> | ||
| <img src="http://localhost:8000/asset/images/hapo.jpg" class="hapo_img" alt=""> |
There was a problem hiding this comment.
tại sao chỗ này dùng link http: vậy anh :@@
There was a problem hiding this comment.
@anhht-hapo a chạy serve nếu k sử dụng http://localhost:8000 thì n không nhận link css.@@
resources/views/index.blade.php
Outdated
| <div class="row"> | ||
| @if(Session::has('thanhcong')) | ||
| <div class="alert alert-success thanh-cong">{{Session::get('thanhcong')}}</div> | ||
| <div class="alert alert-success thanh-cong">{{Session::get('thanhcong')}}</div> |
There was a problem hiding this comment.
sao tên class tiếng việt không dấu vậy anh
| { | ||
| // | ||
| $employee = new Employee(); | ||
| if($request->hasFile('avata')){ |
| return redirect('employs')->with('thanhcong','Xóa nhân viên thành công'); | ||
| } | ||
|
|
||
| public function search(Request $request){ |
There was a problem hiding this comment.
convention dòng này em ơi! {} 2 dấu đóng mở này phải nằm trên 1 dong trắng
| @@ -13,12 +13,12 @@ class EmployeeController extends Controller | |||
| { | |||
| // | |||
| public function show(){ | |||
| return view('admin.employee.index',['employees'=>$employees]); | ||
| } | ||
|
|
||
| public function add(){ |
| $employee->birthday = $request->birthday; | ||
| $employee->email = $request->email; | ||
| $employee->save(); | ||
| return redirect('/show')->with('thanhcong','Thêm nhân viên thành công'); |
There was a problem hiding this comment.
@thiennguyen84 dùng route('name') đi em.ko nên dùng đường dẫn url nữa
| $employee->email = $request->email; | ||
| $employee->save(); | ||
| return redirect('/employs')->with('thanhcong','Thêm nhân viên thành công'); | ||
| return redirect()->route('employs.index')->with('thanhcong','Thêm nhân viên thành công'); |
There was a problem hiding this comment.
@thiennguyen84 cho message này vào file lang em ơi. Đọc doc ở đây em nhé https://laravel.com/docs/5.5/localization
các chỗ tương tự em tự tìm rồi tự cho vào nhé, anh ko comment nữa nhé
(nguyên xi dòng anh chung review của anh. em xem của anh tham khảo nha)
ded0b26 to
4fbfc41
Compare
4fbfc41 to
5fb7bf1
Compare
No description provided.