/**
  *
  * @return \Illuminate\View\View
  */
 public function index()
 {
     $tableOptions = ['id' => 'reader-manage', 'class' => 'table-readers', 'row_index' => true];
     $options = ['aoColumnDefs' => [['sClass' => 'min-width text-right', 'aTargets' => [0, 1]], ['sClass' => 'min-width', 'aTargets' => [-1, -2]]]];
     $table = Datatable::table()->addColumn('', trans('ilib::reader.code_th'), trans('user::user.name'), trans('ilib::reader.security_id'), trans('common.actions'))->setOptions($options)->setCustomValues($tableOptions);
     $name = trans('ilib::reader.reader');
     $this->buildHeading([trans('common.manage'), $name], 'fa-file-pdf-o', ['#' => $name]);
     // 10 users chưa phải là reader
     $selectize_users = User::forSelectize(Reader::all()->pluck('user_id'), 10)->get()->all();
     $reader = new Reader();
     return view('ilib::backend.reader.index', compact('tableOptions', 'options', 'table', 'selectize_users') + $reader->loadEnums('id'));
 }
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     /** @var \Minhbang\User\User $user */
     if ($user = $this->route('user')) {
         //update User
         $this->rules['username'] .= ',username,' . $user->id;
         $this->rules['email'] .= ',email,' . $user->id;
     } else {
         //create User
         $this->rules['password'] .= '|required';
     }
     $this->rules['role'] .= '|in:' . implode(',', array_keys(User::guardedRoleTitles()));
     return $this->rules;
 }
Example #3
0
 /**
  * @param array $data
  */
 public function seed($data)
 {
     DB::table('readers')->truncate();
     $readers = [];
     foreach ($data as $username => $security) {
         /** @var User $user */
         $user = User::findBy('username', $username);
         /** @var Enum $enum */
         $enum = Enum::where('slug', $security)->where('type', 'ebook.security')->first();
         if ($user && $enum) {
             $readers[] = ['user_id' => $user->id, 'security_id' => $enum->id, 'code' => "RD-{$user->id}"];
         }
     }
     if ($readers) {
         DB::table('readers')->insert($readers);
     }
 }
 /**
  * Kiểm tra không được update thông tin của chính mình
  * Hoặc với 'super_admin'
  *
  * @param \Minhbang\User\User $user
  * @param bool $ajax
  */
 protected function checkUser($user, $ajax = false)
 {
     if ($user->isSuperAdmin() || user('id') == $user->id) {
         if ($ajax) {
             die(json_encode(['type' => 'error', 'content' => trans('user::user.invalid_action')]));
         } else {
             abort(403, trans('user::user.invalid_action'));
         }
     }
 }
 /**
  * @return string
  */
 public function role()
 {
     return $this->entity->role && ($title = User::roleTitles($this->entity->role)) ? "<code>{$title}</code>" : '<span class="text-gray">' . trans('user::user.no_role') . '</span>';
 }