Skip to content

CRUD#1

Open
linhlt311 wants to merge 11 commits intomasterfrom
develop
Open

CRUD#1
linhlt311 wants to merge 11 commits intomasterfrom
develop

Conversation

@linhlt311
Copy link
Owner

No description provided.

{
$employees = Employee::paginate(5);
$employees = Employee::orderBy('updated_at','desc')->paginate(5);
// dd($employees);

Choose a reason for hiding this comment

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

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done

Copy link

Choose a reason for hiding this comment

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

@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",

Choose a reason for hiding this comment

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

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ữ

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done

{
return [
'img.required' => 'Profile image is required',
];
Copy link

@hapo-truongpm hapo-truongpm Feb 8, 2018

Choose a reason for hiding this comment

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

trên không có rule cho img mà dưới này lại có message là sao nhỉ

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done

@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>

Choose a reason for hiding this comment

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

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

@TruongPhan16 à tức là hiện thi lỗi trên mỗi cái input hở?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done

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

Choose a reason for hiding this comment

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

thiếu space giữa {{}}

Copy link
Owner Author

Choose a reason for hiding this comment

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

@TruongPhan16 là viết kiểu {{ route('user.store') }} hả anh?

Choose a reason for hiding this comment

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

@linhlt311 ừm

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

@@ -27,7 +27,7 @@ public function rules()
"email" => 'unique:employees|max:255',

Choose a reason for hiding this comment

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

@linhlt311 cái này thì nội dung thông báo lỗi ở đâu vậy

Copy link
Owner Author

Choose a reason for hiding this comment

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

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

@nguyenvanpho nguyenvanpho Feb 11, 2018

Choose a reason for hiding this comment

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

@linhlt311 sao chỗ này vẫn dùng url thế em?

Copy link
Owner Author

Choose a reason for hiding this comment

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

đã fix

<td>{{ $employee->JLPT }}</td>
<td>
<a href="{{url('user')}}/{{$employee->id}}">
<a href="{{ url('user') }}/{{ $employee->id }}">

Choose a reason for hiding this comment

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

dùng route:('name') đi em

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

</td>
<td>
<a href="{{url('user')}}/{{$employee->id}}/edit">
<a href="{{ url('user')}}/{{ $employee->id }}/edit">

Choose a reason for hiding this comment

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

như trên

</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">

Choose a reason for hiding this comment

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

asset('storage/'.$employee->image) cho ngan nhe

Copy link
Owner Author

Choose a reason for hiding this comment

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

ok r day

<!-- /.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">

Choose a reason for hiding this comment

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

cai nay co nen them {{ method_field("UPDATE") }} KHONG NHI

Copy link
Owner Author

Choose a reason for hiding this comment

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

Khong can vi co input _method o duoi r

class Employee extends Model
{
//
protected $fillable = ['name', 'gender', 'email', 'phone_number', 'address', 'JLPT', 'image'];
Copy link

Choose a reason for hiding this comment

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

@linhlt311 không khai báo cái này có sao ko ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

@linhlt311 hạn chế hardcode move 5 vào trong config nhé

Copy link
Owner Author

Choose a reason for hiding this comment

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

Fixed

public function store(StoreEmployeeRequest $request)
{
$data = $request->all();
$data = array_slice($data, 1);
Copy link

Choose a reason for hiding this comment

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

@linhlt311 sao phải làm việc này ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

$data = $request->all();
$data = array_slice($data, 1);
Employee::insert($data);
if (array_key_exists('img', $data)) {
Copy link

Choose a reason for hiding this comment

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

@linhlt311 có cách nào check khác tốt hơn ko ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Fixed. Đổi sang hasFile

public function show($id)
{
$employee = Employee::find($id);
$employee = Employee::findOrFail($id);
Copy link

Choose a reason for hiding this comment

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

@linhlt311 phân biệt giúp a sự khác nhau giữa findfindOrFail

Copy link
Owner Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

@linhlt311 ko validate phần này à ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Fixed


public function updateImage(Request $request, $id) {
$imgLink = $request->file('img')->store('public/images');
$imgLink = substr($imgLink, 7);
Copy link

Choose a reason for hiding this comment

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

@linhlt311 sao lại phải làm thế này ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

@linhlt311 thay hàm where bằng hàm khác đc ko ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Đã đổi thành find

@@ -9,7 +9,6 @@ class UserController extends Controller
{
public function show() {
$employee = Employee::get();
Copy link

Choose a reason for hiding this comment

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

@linhlt311 hàm này có dùng ko e ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Deleted

"name" => "max:255|regex:/^[\p{L}\s'.-]+$/u",
"phone_number" => "min:6|max:20|regex:/^[0-9]*$/",
"address" => "max:255",
];
Copy link

Choose a reason for hiding this comment

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

@linhlt311 thêm cho a phần custom nội dung các message trả về nhé

Copy link
Owner Author

Choose a reason for hiding this comment

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

Added custom message

$table->string('phone_number')->nullable();
$table->string('address')->nullable();
$table->string('JLPT');
$table->text('image');
Copy link

Choose a reason for hiding this comment

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

@linhlt311 trường này có cần dùng đến text ko e ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

@linhlt311 biết es6 chưa e ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Đã đổi sang let

dangerMode: true,
})
.then((willDelete) = > {
.then((willDelete) => {
Copy link

Choose a reason for hiding this comment

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

@linhlt311 có nhất thiết phải viết then đoạn này ko ?

Copy link
Owner Author

@linhlt311 linhlt311 Feb 12, 2018

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

@linhlt311 ko có case error à e ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

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.

6 participants