Exemplo n.º 1
0
 public function store()
 {
     $validator = Validator::make(Request::all(), ['name' => 'required|max:255', 'cname' => 'required|max:10', 'perm' => 'required']);
     if ($validator->fails()) {
         return back()->withErrors($validator)->withInput();
     }
     $id = (int) Request::input('id');
     $pid = (int) Request::input('pid');
     $name = Request::input('name');
     $cname = Request::input('cname');
     $desc = Request::input('desc');
     $perm = Request::input('perm');
     if ($id) {
         $role = Term::find($id);
         //检测类别 不能加到 不同的分类和子分类
         $terms = Term::get_item_by_type('role');
         $terms = array_assort($terms, 'id', 'pid', 0, $id);
         if ($pid && $pid != $role->pid && !in_array($pid, array_keys($terms))) {
             $validator->errors()->add('type', '类别不正确');
             return back()->withErrors($validator)->withInput();
         }
         $role->id = $id;
     } else {
         $role = new Term();
         $role->type = 'role';
     }
     $role->pid = $pid;
     $role->name = $name;
     $role->cname = $cname;
     $role->desc = $desc;
     $role->save();
     $role->set_value_by_key('perm', $perm);
     return redirect()->action('Admin\\RoleController@index');
 }
Exemplo n.º 2
0
 public function edit($id)
 {
     $categories = Term::get_item_by_type('category');
     $tags = Term::get_item_by_type('tag');
     $post = Post::find($id);
     $relations = array_column($post->relations->toArray(), 'term_id');
     return view('post.add', ['post' => $post, 'categories' => $categories, 'tags' => $tags, 'relations' => $relations]);
 }
Exemplo n.º 3
0
 public static function list_paginate($term_id = 0, $term_type = 'category', $per_page = 2)
 {
     if ($term_id) {
         $terms = Term::get_item_by_type($term_type, $term_id);
         $category_ids = array_column($terms, 'id');
         $category_ids[] = $term_id;
         $posts = Post::leftJoin('relations', 'posts.id', '=', 'relations.object_id')->whereIn('relations.term_id', $category_ids)->orderBy('id', 'desc')->paginate($per_page);
     } else {
         $posts = Post::orderBy('id', 'desc')->paginate($per_page);
     }
     return $posts;
 }
Exemplo n.º 4
0
 public function role($rid, $query_rid = 0)
 {
     Debugbar::disable();
     $has_perm = [];
     if ($rid) {
         $role = Term::where('id', $rid)->where('type', 'role')->first();
         $perm_id = $role->perm ?: [];
         $perm = Term::whereIn('id', $perm_id)->get()->toArray();
         if ($query_rid) {
             $query_role = Term::where('id', $query_rid)->where('type', 'role')->first();
             $has_perm = $query_role->perm;
         }
         //$has_perm = $role->perm;
     } else {
         $perm = Term::get_item_by_type('permission');
     }
     return view('perm.perm', ['perms' => $perm, 'has_perm' => $has_perm]);
 }