diff --git a/app/Admin/Controllers/LoginController.php b/app/Admin/Controllers/LoginController.php index 713ef3c..f8a0bbc 100644 --- a/app/Admin/Controllers/LoginController.php +++ b/app/Admin/Controllers/LoginController.php @@ -14,12 +14,14 @@ public function index() //登录操作 public function login(Request $request) { + //验证 $this->validate($request,[ 'email' =>'required|email', 'password' =>'required|min:3|max:10', 'is_remember' =>'integer', ]); + return ; } diff --git a/app/Admin/Controllers/PostController.php b/app/Admin/Controllers/PostController.php index 54517f2..1da7a90 100644 --- a/app/Admin/Controllers/PostController.php +++ b/app/Admin/Controllers/PostController.php @@ -18,9 +18,27 @@ public function index() public function check(Post $post) { - $post->status = request('status'); - dd($post); - return ; + $status = request('status'); + if ($status=='1') { + $affected = $post->update(['status'=>'1']); + }else{ + $affected = $post->update(['status'=>'-1']); + } + + if ($affected>0) { + $success = [ + 'error'=>'0', + 'msg'=>'success' + ]; + echo json_encode($success); + } else { + $error = [ + 'error'=>'1', + 'msg'=>'error' + ]; + echo json_encode($error); + } + } diff --git a/app/Admin/Controllers/UserController.php b/app/Admin/Controllers/UserController.php index ebba8a9..03cc3de 100644 --- a/app/Admin/Controllers/UserController.php +++ b/app/Admin/Controllers/UserController.php @@ -2,6 +2,7 @@ namespace App\Admin\Controllers; use App\AdminUser; +use App\Category; use Illuminate\Http\Request; class UserController extends Controller @@ -31,5 +32,12 @@ public function store(Request $request) return redirect('admin/users'); } + public function test() + { + $res = Category::with('allChildrenCategorys')->where('parent_id',0)->get(); + + dd($res->toArray()); + } + } \ No newline at end of file diff --git a/app/AdminUser.php b/app/AdminUser.php index d4c4c53..72cd075 100644 --- a/app/AdminUser.php +++ b/app/AdminUser.php @@ -3,8 +3,23 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Foundation\Auth\User as Authenticatable; -class AdminUser extends Model +class AdminUser extends Authenticatable { + protected $tables = 'admin_users'; protected $guarded = ['_token']; + //管理员有哪些角色 + public function role() + { + return $this->belongsToMany('\App\Role','admin_roles','user_id','role_id') + ->withPivot('user_id','role_id'); + } + + //是否有某个/些角色,返回的是布尔值 + + public function isInRoles($roles) + { + return !!$roles->intersect($this->role)->count(); + } } diff --git a/app/Category.php b/app/Category.php new file mode 100644 index 0000000..821beb5 --- /dev/null +++ b/app/Category.php @@ -0,0 +1,17 @@ +hasMany('App\Category', 'parent_id', 'id'); + } + + public function allChildrenCategorys() + { + return $this->childCategory()->with('allChildrenCategorys');//with预加载 + } +} diff --git a/app/Permission.php b/app/Permission.php new file mode 100644 index 0000000..9b9e96f --- /dev/null +++ b/app/Permission.php @@ -0,0 +1,10 @@ +belongsToMany('\App\Permission','permission_roles','role_id','permission_id') + ->withPivot('role_id','permission_id'); + } + + +} diff --git a/database/migrations/2017_08_24_091004_create_categories_table.php b/database/migrations/2017_08_24_091004_create_categories_table.php new file mode 100644 index 0000000..52ac32a --- /dev/null +++ b/database/migrations/2017_08_24_091004_create_categories_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->integer('parent_id'); + $table->string('code'); + $table->string('name'); + $table->string('path'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('categories'); + } +} diff --git a/database/migrations/2017_08_25_155608_create_roles_table.php b/database/migrations/2017_08_25_155608_create_roles_table.php new file mode 100644 index 0000000..1f50367 --- /dev/null +++ b/database/migrations/2017_08_25_155608_create_roles_table.php @@ -0,0 +1,33 @@ +increments('id'); + $table->string('name'); + $table->string('description'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('roles'); + } +} diff --git a/database/migrations/2017_08_25_155640_create_permissions_table.php b/database/migrations/2017_08_25_155640_create_permissions_table.php new file mode 100644 index 0000000..8c651ed --- /dev/null +++ b/database/migrations/2017_08_25_155640_create_permissions_table.php @@ -0,0 +1,33 @@ +increments('id'); + $table->string('name'); + $table->string('description'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('permissions'); + } +} diff --git a/database/migrations/2017_08_25_160709_create_admin_roles_table.php b/database/migrations/2017_08_25_160709_create_admin_roles_table.php new file mode 100644 index 0000000..5ff5a44 --- /dev/null +++ b/database/migrations/2017_08_25_160709_create_admin_roles_table.php @@ -0,0 +1,33 @@ +increments('id'); + $table->integer('admin_id'); + $table->integer('role_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('admin_roles'); + } +} diff --git a/database/migrations/2017_08_25_160910_create_permission_roles_table.php b/database/migrations/2017_08_25_160910_create_permission_roles_table.php new file mode 100644 index 0000000..a2e7b19 --- /dev/null +++ b/database/migrations/2017_08_25_160910_create_permission_roles_table.php @@ -0,0 +1,33 @@ +increments('id'); + $table->integer('role_id'); + $table->integer('perm_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('permission_roles'); + } +} diff --git a/public/js/admin.js b/public/js/admin.js index bde370d..4b2449e 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -1,13 +1,41 @@ +$.ajaxSetup({ + headers: { + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') + } +}); -function check(button) { - var post_id=$(button).attr('post-id'); - var status = $(button).attr('post-action-status'); - $.post('posts/'+post_id+'/check',{'status':status},function (res) { - if(res.status==1) { - alert('成功'); - }else if (res.status==0) { - alert('失败'); + +$(".post-audit").click(function (event) { + target = $(event.target); + var post_id= target.attr('post-id'); + var status = target.attr('post-action-status'); + console.log(post_id); + $.ajax({ + url:'/admin/posts/'+post_id+'/check', + method:'POST', + data:{'status':status}, + dataType:'json', + success: function (res) { + if(res.error!= 0){ + alert(res.msg); + return; + } + target.parent().parent().remove(); } - },'json'); -} \ No newline at end of file + }); +}); + + +// function check(button) { +// var post_id=$(button).attr('post-id'); +// var status = $(button).attr('post-action-status'); +// $.post('posts/'+post_id+'/check',{'status':status},function (res) { +// alert(res.status); +// if(res.status==1) { +// alert('成功'); +// }else if (res.status==0) { +// alert('失败'); +// } +// },'json'); +// } \ No newline at end of file diff --git a/resources/views/admin/login/index.blade.php b/resources/views/admin/login/index.blade.php index 4e8ca47..b81693d 100644 --- a/resources/views/admin/login/index.blade.php +++ b/resources/views/admin/login/index.blade.php @@ -49,6 +49,9 @@