public function index()
{
$emp_info= Emp::paginate(2);
return view('admin.emp.index',compact('emp_info'));
}
@foreach($emp_info as $v)
<tr>
<td>{{$v->id}}</td>
<td>{{$v->did}}</td>
<td>{{$v->name}}</td>
<td>{{$v->birth}}</td>
<td>{{$v->entry}}</td>
<td>
<a class="icon icon-edit" href="{{url('index/edit',['id'=>$v->id])}}">编辑</a>
<a class="icon icon-del" href="{{url('index/del',['id'=>$v->id])}}">删除</a>
</td>
</tr>
@endforeach
$data = $request->all();
$this->validate($request,[
'did'=>'required',
'name'=>'required',
'birth'=>'required',
'entry'=>'required',
],[
'did.require'=>'部门不能为空',
'name.require'=>'姓名不能为空',
'birth.require'=>'出生日期不能为空',
'entry.require'=>'入职日期不能为空',
]);
$re = Emp::create($data);
if($re){
return redirect('index')->with('message','添加成功');
}else{
return redirect('index/add')->with('tip','添加失败');
}
if(isset($data['id'])){
$id = $data['id'];
unset($data['id']);
unset($data['_token']);
$res =Emp::where('id',$id)->update($data);
$type = $res ? "message" : "tip";
$message = $res ? "修改成功" : "修改失败";
return redirect('index')->with($type, $message);
}
$id=$request->id;
//dump($emp);
if (!$emp = Emp::find($id)) {
return response()->json(['code' => 0, 'msg' => '删除失败,记录不存在。' ]);
}
$emp->delete();
return redirect('index')->with('message','删除成功');
//删除员工信息
public function del(Request $request)
{
$id=$request->id;
//dump($emp);
if (!$emp = Emp::find($id)) {
return response()->json(['code' => 0, 'msg' => '删除失败,记录不存在。' ]);
}
$emp->delete();
return redirect('index')->with('message','删除成功');
}