Skip to content

Commit

Permalink
0823
Browse files Browse the repository at this point in the history
  • Loading branch information
osramywj committed Aug 23, 2017
1 parent a2e77f5 commit a4c609e
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/Admin/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ public function login(Request $request)
$this->validate($request,[
'email' =>'required|email',
'password' =>'required|min:3|max:10',
'is_remember' =>'integer'
'is_remember' =>'integer',
]);

return ;
}

public function logout()
{

return;
}
}
27 changes: 27 additions & 0 deletions app/Admin/Controllers/PostController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace App\Admin\Controllers;


use App\Post;
use Illuminate\Support\Facades\DB;

class PostController extends Controller
{
//文章审核页面
public function index()
{
// $posts = DB::table('posts')->where('status',0)->get();
$posts = Post::withoutGlobalScope('available')->where('status',0)->get();
// dd($posts);
return view('admin.post.index',compact('posts'));
}

public function check(Post $post)
{
$post->status = request('status');
dd($post);
return ;
}


}
35 changes: 35 additions & 0 deletions app/Admin/Controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace App\Admin\Controllers;

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

class UserController extends Controller
{
//管理员列表页面
public function index()
{
$users = AdminUser::paginate(10);
return view('admin.user.index',compact('users'));
}

public function create()
{
return view('admin.user.create');
}

public function store(Request $request)
{
$this->validate($request,[
'name' =>'required',
'password' =>'required|min:3|max:10',
]);
$name = request('name');
$password = bcrypt(request('password'));
$res = AdminUser::firstOrCreate(compact('name'));
$res && AdminUser::where('id',$res->id)->update(compact('password'));
return redirect('admin/users');
}


}
10 changes: 10 additions & 0 deletions app/AdminUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class AdminUser extends Model
{
protected $guarded = ['_token'];
}
9 changes: 9 additions & 0 deletions app/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ class Post extends Model
{
protected $guarded = ['_token'];

protected static function boot()
{
parent::boot();

static::addGlobalScope('available', function (\Illuminate\Database\Eloquent\Builder $builder) {
$builder->whereIn('status',[0,1]);
});
}

public function user()
{
return $this->belongsTo('App\User','user_id','id');
Expand Down
34 changes: 34 additions & 0 deletions database/migrations/2017_08_23_135046_create_admin_users_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

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

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

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

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

class AlterPostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->tinyInteger('status')->default(0);//0 未知 1审核通过 -1已删除
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('posts', function (Blueprint $table) {
$table->dropColumn('status');
});
}
}
13 changes: 13 additions & 0 deletions public/js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


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('失败');
}
},'json');
}
2 changes: 1 addition & 1 deletion resources/views/admin/layout/main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="csrf-token" content="RPPMc0lhvtynKELDZljXlz9UZI9uNc55ip1P8GCM">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>AdminLTE 2 | Dashboard</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
Expand Down
41 changes: 41 additions & 0 deletions resources/views/admin/post/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@extends('admin.layout.main')
@section('content')
<div class="content-wrapper">

<!-- Main content -->
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-10 col-xs-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">文章列表</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table class="table table-bordered">
<tbody><tr>
<th style="width: 10px">#</th>
<th>文章标题</th>
<th>操作</th>
</tr>
@foreach($posts as $key=>$post)
<tr>
<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>
</td>
</tr>
@endforeach
</tbody></table>
</div>

</div>
</div>
</div>
</section>
<!-- /.content -->
</div>
@endsection
43 changes: 43 additions & 0 deletions resources/views/admin/user/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@extends('admin.layout.main')
@section('content')
<div class="content-wrapper">

<!-- Main content -->
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-10 col-xs-6">
<div class="box">

<!-- /.box-header -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">增加用户</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form role="form" action="/admin/users/store" method="POST">
{{csrf_field()}}
<div class="box-body">
<div class="form-group">
<label for="exampleInputEmail1">用户名</label>
<input type="text" class="form-control" name="name" placeholder="Name">
</div>
<div class="form-group">
<label for="exampleInputPassword1">密码</label>
<input type="password" class="form-control" placeholder="Password" name="password">
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">提交</button>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<!-- /.content -->
</div>
@endsection
43 changes: 43 additions & 0 deletions resources/views/admin/user/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@extends('admin.layout.main')
@section('content')
<div class="content-wrapper">

<!-- Main content -->
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-10 col-xs-6">
<div class="box">

<div class="box-header with-border">
<h3 class="box-title">用户列表</h3>
</div>
<a type="button" class="btn " href="/admin/users/create" >增加用户</a>
<!-- /.box-header -->
<div class="box-body">
<table class="table table-bordered">
<tbody><tr>
<th style="width: 10px">#</th>
<th>用户名称</th>
<th>操作</th>
</tr>
@foreach($users as $key=>$user)
<tr>
<td>{{$key+1}}.</td>
<td>{{$user->name}}</td>
<td>
<a type="button" class="btn" href="/admin/users/{{$user->id}}/role" >角色管理</a>
</td>
</tr>
@endforeach
</tbody></table>
{{$users->links()}}
</div>

</div>
</div>
</div>
</section>
<!-- /.content -->
</div>
@endsection
13 changes: 13 additions & 0 deletions routes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,17 @@
Route::post('/login','\App\Admin\Controllers\LoginController@login');
Route::get('/logout','\App\Admin\Controllers\LoginController@logout');
Route::get('/home','\App\Admin\Controllers\HomeController@index');

//管理人员列表页面
Route::get('users','\App\Admin\Controllers\UserController@index');
//添加管理员页面
Route::get('users/create','\App\Admin\Controllers\UserController@create');
//添加管理员操作
Route::post('users/store','\App\Admin\Controllers\UserController@store');

//审核页面
Route::get('posts','\App\Admin\Controllers\PostController@index');
//审核动作
Route::post('posts/{$post}/check','\App\Admin\Controllers\PostController@check');

});
2 changes: 2 additions & 0 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
$baseDir = dirname($vendorDir);

return array(
'AlterPostsTable' => $baseDir . '/database/migrations/2017_08_23_153602_alter_posts_table.php',
'CreateAdminUsersTable' => $baseDir . '/database/migrations/2017_08_23_135046_create_admin_users_table.php',
'CreateCommentsTable' => $baseDir . '/database/migrations/2017_08_11_163558_create_comments_table.php',
'CreateFansTable' => $baseDir . '/database/migrations/2017_08_12_151845_create_fans_table.php',
'CreatePasswordResetsTable' => $baseDir . '/database/migrations/2014_10_12_100000_create_password_resets_table.php',
Expand Down
2 changes: 2 additions & 0 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ class ComposerStaticInitf552daa799ac2a29694936bdf07fc081
);

public static $classMap = array (
'AlterPostsTable' => __DIR__ . '/../..' . '/database/migrations/2017_08_23_153602_alter_posts_table.php',
'CreateAdminUsersTable' => __DIR__ . '/../..' . '/database/migrations/2017_08_23_135046_create_admin_users_table.php',
'CreateCommentsTable' => __DIR__ . '/../..' . '/database/migrations/2017_08_11_163558_create_comments_table.php',
'CreateFansTable' => __DIR__ . '/../..' . '/database/migrations/2017_08_12_151845_create_fans_table.php',
'CreatePasswordResetsTable' => __DIR__ . '/../..' . '/database/migrations/2014_10_12_100000_create_password_resets_table.php',
Expand Down

0 comments on commit a4c609e

Please sign in to comment.