Conversation
| { | ||
| $employees = Employee::paginate(5); | ||
| $employees = Employee::orderBy('updated_at','desc')->paginate(5); | ||
| // dd($employees); |
There was a problem hiding this comment.
bỏ dd đi em, nếu như chỉ có 1 biến thì không cần cho vào mảng data cũng đc
There was a problem hiding this comment.
@linhlt311 Done mà sao vẫn còn dd thế này em ?
| return [ | ||
| "email" => 'unique:employees|max:255', | ||
| "name" => "max:255", | ||
| "phone" => "max:255", |
There was a problem hiding this comment.
name như này là nhập được cả số cả các ký tự đặc biệt à
phone thì nhập được cả chữ
| { | ||
| return [ | ||
| 'img.required' => 'Profile image is required', | ||
| ]; |
There was a problem hiding this comment.
trên không có rule cho img mà dưới này lại có message là sao nhỉ
| @foreach ($errors->all() as $error) | ||
| <li>{{ $error }}</li> | ||
| @endforeach | ||
| </ul> |
There was a problem hiding this comment.
anh nghĩ là nên cho mỗi error vào từng input tương ứng thay vì hiện ra tất như này
There was a problem hiding this comment.
@TruongPhan16 à tức là hiện thi lỗi trên mỗi cái input hở?
| @endif | ||
| <!-- form start --> | ||
| <form role="form" action="{{route('user.store')}}" method="post"> | ||
| <form role="form" action="{{route('user.store')}}" method="post" enctype="multipart/form-data"> |
There was a problem hiding this comment.
@TruongPhan16 là viết kiểu {{ route('user.store') }} hả anh?
| @@ -27,7 +27,7 @@ public function rules() | |||
| "email" => 'unique:employees|max:255', | |||
There was a problem hiding this comment.
@linhlt311 cái này thì nội dung thông báo lỗi ở đâu vậy
There was a problem hiding this comment.
@thiennguyen84 là sao nhỉ? cái này em k làm error message, dùng luôn default của nó
| <!-- form start --> | ||
| <form role="form" action="{{url('user')}}/{{$employee->id}}" method="post"> | ||
| {{csrf_field()}} | ||
| <form role="form" action="{{ url('user') }}/{{ $employee->id }}" method="post"> |
There was a problem hiding this comment.
@linhlt311 sao chỗ này vẫn dùng url thế em?
| <td>{{ $employee->JLPT }}</td> | ||
| <td> | ||
| <a href="{{url('user')}}/{{$employee->id}}"> | ||
| <a href="{{ url('user') }}/{{ $employee->id }}"> |
| </td> | ||
| <td> | ||
| <a href="{{url('user')}}/{{$employee->id}}/edit"> | ||
| <a href="{{ url('user')}}/{{ $employee->id }}/edit"> |
| </div> | ||
| <div class="box-body"> | ||
| <img class="profile-user-img img-responsive img-circle" src="{{ url('storage') }}/{{ $employee->image }}" alt="User profile picture"> | ||
| <img class="profile-user-img img-responsive img-circle" src="{{ asset('storage') }}/{{ $employee->image }}" alt="User profile picture"> |
There was a problem hiding this comment.
asset('storage/'.$employee->image) cho ngan nhe
| <!-- /.box-header --> | ||
| <!-- form start --> | ||
| <form role="form" action="{{ route('user.edit', $employee->id) }}" method="post"> | ||
| <form role="form" action="{{ route('user.update', $employee->id) }}" method="post"> |
There was a problem hiding this comment.
cai nay co nen them {{ method_field("UPDATE") }} KHONG NHI
There was a problem hiding this comment.
Khong can vi co input _method o duoi r
| class Employee extends Model | ||
| { | ||
| // | ||
| protected $fillable = ['name', 'gender', 'email', 'phone_number', 'address', 'JLPT', 'image']; |
There was a problem hiding this comment.
@linhlt311 không khai báo cái này có sao ko ?
There was a problem hiding this comment.
@damnnkst nếu bỏ đi thì em không add mới đc anh ạ
| public function index() | ||
| { | ||
| $employees = Employee::paginate(5); | ||
| $employees = Employee::orderBy('updated_at','desc')->paginate(5); |
There was a problem hiding this comment.
@linhlt311 hạn chế hardcode move 5 vào trong config nhé
| public function store(StoreEmployeeRequest $request) | ||
| { | ||
| $data = $request->all(); | ||
| $data = array_slice($data, 1); |
| $data = $request->all(); | ||
| $data = array_slice($data, 1); | ||
| Employee::insert($data); | ||
| if (array_key_exists('img', $data)) { |
There was a problem hiding this comment.
@linhlt311 có cách nào check khác tốt hơn ko ?
There was a problem hiding this comment.
Fixed. Đổi sang hasFile
| public function show($id) | ||
| { | ||
| $employee = Employee::find($id); | ||
| $employee = Employee::findOrFail($id); |
There was a problem hiding this comment.
@linhlt311 phân biệt giúp a sự khác nhau giữa find và findOrFail
There was a problem hiding this comment.
@damnnkst find không trùng thì nó trả lại null còn findOrFail không trùng thì nó throw error anh ơi
| } | ||
|
|
||
| public function updateImage(Request $request, $id) { | ||
| $imgLink = $request->file('img')->store('public/images'); |
|
|
||
| public function updateImage(Request $request, $id) { | ||
| $imgLink = $request->file('img')->store('public/images'); | ||
| $imgLink = substr($imgLink, 7); |
There was a problem hiding this comment.
@damnnkst em cut cái chữ public/ ở đâu đi để về sau gọi ảnh cho nó dễ ạ
| $imgLink = $request->file('img')->store('public/images'); | ||
| $imgLink = substr($imgLink, 7); | ||
| $data["image"] = $imgLink; | ||
| Employee::where('id',$id)->update($data); |
There was a problem hiding this comment.
@linhlt311 thay hàm where bằng hàm khác đc ko ?
| @@ -9,7 +9,6 @@ class UserController extends Controller | |||
| { | |||
| public function show() { | |||
| $employee = Employee::get(); | |||
| "name" => "max:255|regex:/^[\p{L}\s'.-]+$/u", | ||
| "phone_number" => "min:6|max:20|regex:/^[0-9]*$/", | ||
| "address" => "max:255", | ||
| ]; |
There was a problem hiding this comment.
@linhlt311 thêm cho a phần custom nội dung các message trả về nhé
| $table->string('phone_number')->nullable(); | ||
| $table->string('address')->nullable(); | ||
| $table->string('JLPT'); | ||
| $table->text('image'); |
There was a problem hiding this comment.
@linhlt311 trường này có cần dùng đến text ko e ?
There was a problem hiding this comment.
@damnnkst em nghĩ nên để text vì có khả năng là cái link ảnh nó dài ạ
| function readURL(input) { | ||
|
|
||
| if (input.files && input.files[0]) { | ||
| var reader = new FileReader(); |
| dangerMode: true, | ||
| }) | ||
| .then((willDelete) = > { | ||
| .then((willDelete) => { |
There was a problem hiding this comment.
@linhlt311 có nhất thiết phải viết then đoạn này ko ?
There was a problem hiding this comment.
@damnnkst cái này em làm theo document của nó thôi ạ. Nhưng mà then thì nó mới chạy cái ajax chứ nhỉ
| $.ajax({ | ||
| type: 'delete', | ||
| url: 'user/' + id, | ||
| success: function (response) { |
No description provided.