Skip to content

Commit

Permalink
0825
Browse files Browse the repository at this point in the history
  • Loading branch information
osramywj committed Aug 25, 2017
1 parent a4c609e commit 81d6673
Show file tree
Hide file tree
Showing 19 changed files with 317 additions and 18 deletions.
2 changes: 2 additions & 0 deletions app/Admin/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
}

Expand Down
24 changes: 21 additions & 3 deletions app/Admin/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}


Expand Down
8 changes: 8 additions & 0 deletions app/Admin/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace App\Admin\Controllers;

use App\AdminUser;
use App\Category;
use Illuminate\Http\Request;

class UserController extends Controller
Expand Down Expand Up @@ -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());
}


}
17 changes: 16 additions & 1 deletion app/AdminUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
17 changes: 17 additions & 0 deletions app/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
public function childCategory() {
return $this->hasMany('App\Category', 'parent_id', 'id');
}

public function allChildrenCategorys()
{
return $this->childCategory()->with('allChildrenCategorys');//with预加载
}
}
10 changes: 10 additions & 0 deletions app/Permission.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Permission extends Model
{
protected $guarded = ['_token'];
}
18 changes: 18 additions & 0 deletions app/Role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
protected $guarded = ['_token'];

public function permission()
{
return $this->belongsToMany('\App\Permission','permission_roles','role_id','permission_id')
->withPivot('role_id','permission_id');
}


}
35 changes: 35 additions & 0 deletions database/migrations/2017_08_24_091004_create_categories_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->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');
}
}
33 changes: 33 additions & 0 deletions database/migrations/2017_08_25_155608_create_roles_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('roles');
}
}
33 changes: 33 additions & 0 deletions database/migrations/2017_08_25_155640_create_permissions_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePermissionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('permissions');
}
}
33 changes: 33 additions & 0 deletions database/migrations/2017_08_25_160709_create_admin_roles_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAdminRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_roles', function (Blueprint $table) {
$table->increments('id');
$table->integer('admin_id');
$table->integer('role_id');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('admin_roles');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePermissionRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('permission_roles', function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id');
$table->integer('perm_id');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('permission_roles');
}
}
48 changes: 38 additions & 10 deletions public/js/admin.js
Original file line number Diff line number Diff line change
@@ -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');
}
});
});


// 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');
// }
3 changes: 3 additions & 0 deletions resources/views/admin/login/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">登陆</button>
</div>
<a href="https://open.weixin.qq.com/connect/qrconnect?appid=your appid &redirect_uri=http://www.sunmil.cn/passport-linshi.html&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect" rel="external nofollow" >微信登录</a>
<br><br>

<!-- /.col -->
</div>
</form>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/admin/post/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<td>{{$key+1}}</td>
<td><a href="{{url('posts/'.$post->id.'')}}">{{$post->title}}</a> </td>
<td>
<button type="button" class="btn btn-block btn-default post-audit" post-id="{{$post->id}}" onclick="check(this)" post-action-status="1" >通过</button>
<button type="button" class="btn btn-block btn-default post-audit" post-id="{{$post->id}}" onclick="check(this)" post-action-status="-1" >拒绝</button>
<button type="button" class="btn btn-block btn-default post-audit" post-id="{{$post->id}}" post-action-status="1" >通过</button>
<button type="button" class="btn btn-block btn-default post-audit" post-id="{{$post->id}}" post-action-status="-1" >拒绝</button>
</td>
</tr>
@endforeach
Expand Down
2 changes: 1 addition & 1 deletion routes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
//审核页面
Route::get('posts','\App\Admin\Controllers\PostController@index');
//审核动作
Route::post('posts/{$post}/check','\App\Admin\Controllers\PostController@check');
Route::post('posts/{post}/check','\App\Admin\Controllers\PostController@check');

});
Loading

0 comments on commit 81d6673

Please sign in to comment.