Exemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->input();
     if (empty($data['name'])) {
         $this->hht_alert('add_message', 'danger', '请填写角色名称');
         $this->hht_response_execute();
     }
     if (!isset($data['id'])) {
         $count = DataRole::where('name', $data['name'])->where('status', Config::get("hthou.status_normal"))->count();
         if ($count > 0) {
             $this->hht_alert('add_message', 'danger', '您要添加的角色已存在,请更换');
             $this->hht_response_execute();
         }
         $role_data = new DataRole();
         $role_data->name = $data['name'];
         $role_data->privilege = '[]';
         $role_data->description = $data['description'];
         $role_data->addtime = time();
         $role_data->listorder = 0;
         $role_data->status = Config::get("hthou.status_normal");
         $role_data->save();
     } else {
         $role_data = DataRole::find($data['id']);
         $role_data->name = $data['name'];
         $role_data->description = $data['description'];
         $role_data->save();
     }
     $this->hht_alert_ok('info', '角色信息保存成功');
     $this->hht_response_execute();
 }