AdminUserModel.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. *------------------------------------------------------
  4. * AdminUserModel.php
  5. *------------------------------------------------------
  6. *
  7. * @author m@9026.com
  8. * @date 2017/03/21 10:15
  9. * @version V1.0
  10. *
  11. */
  12. namespace App\Models;
  13. use Illuminate\Foundation\Auth\User as Authenticatable;
  14. use Illuminate\Http\Request;
  15. use Illuminate\Support\Facades\Auth;
  16. use Illuminate\Support\Facades\Validator;
  17. class AdminUserModel extends Authenticatable
  18. {
  19. /**
  20. * 数据表名
  21. */
  22. protected $table = "admin_users";
  23. /**
  24. * 主键
  25. */
  26. protected $primaryKey = "id";
  27. protected $guarded = [];
  28. public function getValidator(Request $request, $type)
  29. {
  30. if ($type == 'store') {
  31. $validator = Validator::make($request->input('data'), [
  32. 'name' => 'required'
  33. ], [
  34. 'name.required' => '账号必填'
  35. ]);
  36. } else if ($type == 'change-password') {
  37. $validator = Validator::make($request->input('data'), [
  38. 'old_password' => 'required',
  39. 'password' => 'required|min:6|confirmed'
  40. ], [
  41. 'old_password.required' => '请填写原来密码',
  42. 'password.required' => '密码必填,且不能少于6位',
  43. 'password.min' => '密码必填,且不能少于6位',
  44. 'password.confirmed' => '两次填写的密码不一致'
  45. ]);
  46. } else {
  47. $validator = Validator::make($request->input('data'), [
  48. 'name' => 'required'
  49. ], [
  50. 'name.required' => '账号必填'
  51. ]);
  52. }
  53. return $validator;
  54. }
  55. public function adminRole()
  56. {
  57. return $this->belongsTo('App\Models\AdminRoleModel', 'admin_role_id');
  58. }
  59. }