示例#1
0
 public function edit($id)
 {
     $group = Group::findOrFail($id);
     if (Request::isMethod('get')) {
         return view('admin.group_edit', ['group' => $group]);
     }
     $validator = Validator::make(Request::all(), $this->rules, $this->messages);
     if ($validator->fails()) {
         return redirect()->route('group_edit', [$id])->withInput()->withErrors($validator);
     }
     $group->title = Request::input('title');
     $group->titleEng = Request::input('titleEng');
     $group->text = Request::input('text');
     $group->eng = Request::input('eng');
     $group->link = Request::input('link');
     $group->position = Request::input('position');
     $group->enabled = Request::has('enabled');
     if ($file = Request::file('photo')) {
         $group->photo = $this->upload($file, 'photo');
     }
     if ($file = Request::file('partners')) {
         $group->partners = $this->upload($file, 'photo');
     }
     $group->save();
     return redirect()->route('group_edit', [$id])->with('msg', 'Изменения сохранены');
 }
示例#2
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit(Request $request, $id)
 {
     //
     $oGroup = Group::findOrFail($id);
     // 需要更新的组
     $powers = Group::get_group_power($id);
     // 组拥有的权限
     $oAllPowers = Power::select(['id', 'category', 'name'])->get();
     // 全部的权限
     // 按分类分开
     $aCategoryPowers = array();
     foreach ($oAllPowers as $k => $v) {
         $aCategoryPowers[$v->category][] = ['id' => $v->id, 'name' => $v->name];
     }
     if ($request->isMethod('get')) {
         return view('admin.group.edit', ['group' => $oGroup, 'power_categorys' => $aCategoryPowers, 'powers' => $powers]);
     }
     // post
     $sGroupName = $request->input('groupname', $oGroup->groupname);
     $aGroupPower = $request->input('powers', array());
     $aAllPowers = array_column($oAllPowers->toArray(), 'id');
     try {
         $j = count($aGroupPower);
         for ($i = 0; $i < $j; $i++) {
             $aGroupPower[$i] = intval($aGroupPower[$i]);
             if (!in_array($aGroupPower[$i], $aAllPowers)) {
                 // 权限不存在
                 unset($aGroupPower[$i]);
             }
         }
     } catch (Exception $e) {
         App::abort(404);
     }
     // 超级管理员的权限永远是所有,无法更改的
     // 只有名字可以修改
     if ($oGroup->id != 1) {
         Group::update_powers($id, $aGroupPower);
     }
     $oGroup->save();
     session()->flash('msg_success', '修改成功');
     return back();
 }
示例#3
0
 public function getGroup()
 {
     $group = Group::findOrFail(static::user()->group_id);
     return $group->name;
 }