Commit 75932c50 authored by gxx's avatar gxx

新增用户权限表

parent 05d76b0c
...@@ -2,17 +2,48 @@ ...@@ -2,17 +2,48 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Role;
use App\Models\User;
use App\Util\Message;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class AuthController extends Controller class AuthController extends Controller
{ {
public function add()
{
// $result =false;
// try{
// $owner = new Role();
// $owner->name = '第10权限';
// $owner->display_name = '这是最最最最厉害的3权限';
// $owner->description = 'heihh';
// $owner->save();
// $result = true;
// }catch (\Exception $e){
// // 生成日志;
// }
// if ($result){
// return Message::makeSuccess('6666');
// }
// return Message::makeError('2333333');
//
// $user = User::where('id','=','2')->first();
//
// $user->attachRole('1');
//
// dd($user);
}
public function getAll() public function getAll()
{ {
echo 123; $roles = Role::paginate(6);
return view('admin/auth/authtables',compact('roles'));
return view('admin/auth/authtables');
} }
} }
<?php
/**
* Created by PhpStorm.
* User: Aladin
* Date: 2017/10/12
* Time: 14:07
*/
namespace App\Models;
use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole
{
}
\ No newline at end of file
...@@ -4,10 +4,16 @@ namespace App\Models; ...@@ -4,10 +4,16 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Zizaco\Entrust\Traits\EntrustRoleTrait as EntrustUserTrait;
class User extends Model class User extends Model
{ {
use SoftDeletes; use Notifiable;
use EntrustUserTrait { restore as private restoreA; }
use SoftDeletes { restore as private restoreB; }
protected $dates = ['delete_at']; protected $dates = ['delete_at'];
protected $hidden =['password']; protected $hidden =['password'];
...@@ -38,4 +44,10 @@ class User extends Model ...@@ -38,4 +44,10 @@ class User extends Model
{ {
return $this->hasMany('App\Models\Schedule','creator_id','id'); return $this->hasMany('App\Models\Schedule','creator_id','id');
} }
public function restore()
{
$this->restoreA();
$this->restoreB();
}
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "31667d774c1e0cb4754ae6075f8d724d", "content-hash": "d4e3e944fa48764ff2615b64aecbebe5",
"packages": [ "packages": [
{ {
"name": "dnoegel/php-xdg-base-dir", "name": "dnoegel/php-xdg-base-dir",
...@@ -2463,6 +2463,74 @@ ...@@ -2463,6 +2463,74 @@
"environment" "environment"
], ],
"time": "2016-09-01T10:05:43+00:00" "time": "2016-09-01T10:05:43+00:00"
},
{
"name": "zizaco/entrust",
"version": "5.2.x-dev",
"source": {
"type": "git",
"url": "https://github.com/Zizaco/entrust.git",
"reference": "3623cc052937d9e62543402b50f24065720d44b9"
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/Zizaco/entrust/3623cc052937d9e62543402b50f24065720d44b9.zip",
"reference": "3623cc052937d9e62543402b50f24065720d44b9",
"shasum": ""
},
"require": {
"illuminate/cache": "~5.0",
"illuminate/console": "~5.0",
"illuminate/support": "~5.0",
"php": ">=5.5.0"
},
"require-dev": {
"illuminate/database": "~5.0",
"mockery/mockery": "dev-master",
"phpunit/phpunit": "~4.1",
"sami/sami": "dev-master"
},
"type": "library",
"autoload": {
"classmap": [
"src/commands"
],
"psr-4": {
"Zizaco\\Entrust\\": "src/Entrust/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Andrew Elkins",
"homepage": "http://andrewelkins.com"
},
{
"name": "Zizaco Zizuini",
"email": "zizaco@gmail.com"
},
{
"name": "Ben Batschelet",
"homepage": "http://github.com/bbatsche"
},
{
"name": "Michele Angioni",
"email": "michele.angioni@gmail.com"
}
],
"description": "This package provides a flexible way to add Role-based Permissions to Laravel",
"keywords": [
"acl",
"auth",
"illuminate",
"laravel",
"permission",
"roles"
],
"time": "2016-12-29T06:25:06+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [
...@@ -4139,7 +4207,9 @@ ...@@ -4139,7 +4207,9 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": {
"zizaco/entrust": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
......
...@@ -186,6 +186,7 @@ return [ ...@@ -186,6 +186,7 @@ return [
App\Providers\SMSServiceProvider::class, App\Providers\SMSServiceProvider::class,
App\Providers\UserServiceProvider::class, App\Providers\UserServiceProvider::class,
Zizaco\Entrust\EntrustServiceProvider::class,
...@@ -238,6 +239,9 @@ return [ ...@@ -238,6 +239,9 @@ return [
'Validator' => Illuminate\Support\Facades\Validator::class, 'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class, 'View' => Illuminate\Support\Facades\View::class,
'Entrust' => Zizaco\Entrust\EntrustFacade::class,
], ],
]; ];
...@@ -68,12 +68,13 @@ return [ ...@@ -68,12 +68,13 @@ return [
'users' => [ 'users' => [
'driver' => 'eloquent', 'driver' => 'eloquent',
'model' => App\User::class, 'model' => App\User::class,
'table' => 'users',
], ],
// 'users' => [ // 'users' => [
// 'driver' => 'database', // 'driver' => 'database',
// 'table' => 'users', // 'table' => 'users',
// ], // ],
], ],
/* /*
......
<?php
/**
* This file is part of Entrust,
* a role & permission management solution for Laravel.
*
* @license MIT
* @package Zizaco\Entrust
*/
return [
/*
|--------------------------------------------------------------------------
| Entrust Role Model
|--------------------------------------------------------------------------
|
| This is the Role model used by Entrust to create correct relations. Update
| the role if it is in a different namespace.
|
*/
'role' => 'App\Role',
/*
|--------------------------------------------------------------------------
| Entrust Roles Table
|--------------------------------------------------------------------------
|
| This is the roles table used by Entrust to save roles to the database.
|
*/
'roles_table' => 'roles',
/*
|--------------------------------------------------------------------------
| Entrust Permission Model
|--------------------------------------------------------------------------
|
| This is the Permission model used by Entrust to create correct relations.
| Update the permission if it is in a different namespace.
|
*/
'permission' => 'App\Permission',
/*
|--------------------------------------------------------------------------
| Entrust Permissions Table
|--------------------------------------------------------------------------
|
| This is the permissions table used by Entrust to save permissions to the
| database.
|
*/
'permissions_table' => 'permissions',
/*
|--------------------------------------------------------------------------
| Entrust permission_role Table
|--------------------------------------------------------------------------
|
| This is the permission_role table used by Entrust to save relationship
| between permissions and roles to the database.
|
*/
'permission_role_table' => 'permission_role',
/*
|--------------------------------------------------------------------------
| Entrust role_user Table
|--------------------------------------------------------------------------
|
| This is the role_user table used by Entrust to save assigned roles to the
| database.
|
*/
'role_user_table' => 'role_user',
/*
|--------------------------------------------------------------------------
| User Foreign key on Entrust's role_user Table (Pivot)
|--------------------------------------------------------------------------
*/
'user_foreign_key' => 'user_id',
/*
|--------------------------------------------------------------------------
| Role Foreign key on Entrust's role_user Table (Pivot)
|--------------------------------------------------------------------------
*/
'role_foreign_key' => 'role_id',
];
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class EntrustSetupTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Create table for storing roles
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->string('display_name')->nullable();
$table->string('description')->nullable();
$table->timestamps();
});
// Create table for associating roles to users (Many-to-Many)
Schema::create('role_user', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')
->onUpdate('cascade')->onDelete('cascade');
$table->primary(['user_id', 'role_id']);
});
// Create table for storing permissions
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->string('display_name')->nullable();
$table->string('description')->nullable();
$table->timestamps();
});
// Create table for associating permissions to roles (Many-to-Many)
Schema::create('permission_role', function (Blueprint $table) {
$table->integer('permission_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->foreign('permission_id')->references('id')->on('permissions')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')
->onUpdate('cascade')->onDelete('cascade');
$table->primary(['permission_id', 'role_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('permission_role');
Schema::drop('permissions');
Schema::drop('role_user');
Schema::drop('roles');
}
}
@extends('admin/dashboard')
@section('content')
<!-- general form elements -->
<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="{{url('auth/add')}}" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<div class="box-body">
<div class="form-group">
<label for="exampleInputFile">头像</label>
<p>
<img src="{{asset($result['head_icon'])}}" alt="" width="100px" height="80px" style="border-radius: 80%">
</p>
</div>
<div class="form-group">
<label for="exampleInputEmail1">用户名</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="User_email" name="user_name" value="{{$result['user_name']}}">
<input type="hidden" name="id" value="{{$result['id']}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">真实姓名</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Real_name" name="real_name" value="{{$result['real_name']}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">手机</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Phone" name="phone" value="{{$result['phone']==''?'':$result['phone']}}">
</div>
<div class="form-group">
<label for="exampleInputEmail1">性别</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="Gender" name="gender" value="{{$result['gender']==0?'男':'女'}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">邮箱</label>
<input type="email" class="form-control" id="exampleInputPassword1" placeholder="Email" name="email" value="{{$result['email']==''?'':$result['email']}}">
</div>
<div class="form-group">
<label for="exampleInputFile">更换头像</label>
<input type="file" id="exampleInputFile" name="head_icon" >
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">保存</button>
</div>
</form>
</div>
<script src="{{url('js/jquery-3.2.1.min.js')}}"> </script>
{{--<script>--}}
{{--$("#exampleInputFile").change(function(){--}}
{{--var file = this.files[0];--}}
{{--// 判断文件大小--}}
{{--if(file.size > 5*1024*1024){--}}
{{--alert('文件过大!');--}}
{{--}--}}
{{--// 使用FileReader 接口--}}
{{--var reader = new FileReader();--}}
{{--// 成功读取--}}
{{--reader.onload = function(){--}}
{{--// 通过reader.result 属性 来访问生成的 base 64 DataURL--}}
{{--var fileInfo = reader.result;--}}
{{--$('#Preview').attr('src',fileInfo).css({width:100,height:90});--}}
{{--//console.log(fileInfo);--}}
{{--var name = $('#exampleInputFile').val();--}}
{{--// 分割字符串--}}
{{--var arr = name.split('\\');--}}
{{--var fileName = arr[arr.length-1];--}}
{{--base64_uploading(fileInfo,fileName);--}}
{{--}--}}
{{--reader.readAsDataURL(file);--}}
{{--})--}}
{{--//AJAX 上传base 64--}}
{{--function base64_uploading(base64Data,fileName){--}}
{{--$.ajax({--}}
{{--type: 'post',--}}
{{--url: "{{url('user/update')}}",--}}
{{--data: {--}}
{{--'base64':base64Data,--}}
{{--'name':fileName--}}
{{--},--}}
{{--dataType:"json",--}}
{{--headers: {--}}
{{--'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')--}}
{{--},--}}
{{--success:function(data){--}}
{{--console.log(data);--}}
{{--if (data ==1 ){--}}
{{--alert('上传成功')--}}
{{--}else {--}}
{{--alert('上传失败')--}}
{{--}--}}
{{--},--}}
{{--error:function (data) {--}}
{{--alert(1);--}}
{{--console.log(data);--}}
{{--}--}}
{{--})--}}
{{--}--}}
{{--</script>--}}
@endsection
\ No newline at end of file
...@@ -47,32 +47,29 @@ ...@@ -47,32 +47,29 @@
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>权限名称</th> <th>角色唯一标识</th>
<th>创建者</th> <th>角色名</th>
<th>简介</th> <th>角色描述</th>
<th>cover_img</th>
<th>操作</th> <th>操作</th>
</tr> </tr>
</thead> </thead>
{{--@if($projects == null)--}} @if($roles == null)
{{--<tbody>--}} <tbody>
{{--<tr>--}} <tr>
{{--<td colspan="8" style="text-align: center;color: red"> 数据暂无 </td>--}} <td colspan="8" style="text-align: center;color: red"> 数据暂无 </td>
{{--</tr>--}} </tr>
{{--</tbody>--}} </tbody>
{{--</table>--}} </table>
{{--@else--}} @else
{{--@foreach($projects as $project)--}} @foreach($roles as $role)
<tbody> <tbody>
<tr> <tr>
<td>1</td> <td>{{$role['id']}}</td>
<td>上天权限</td> <td>{{$role['name']}}</td>
<td></td> <td>{{$role['display_name']}}</td>
<td></td> <td>{{$role['description']}}</td>
<td><img src="" alt="" width="50px" height="40px"> </td>
<td> <td>
<a href="" class="btn btn-info" > 查看详情 </a> <a href="" class="btn btn-info" > 查看详情 </a>
...@@ -81,9 +78,9 @@ ...@@ -81,9 +78,9 @@
</td> </td>
</tr> </tr>
</tbody> </tbody>
{{--@endforeach--}} @endforeach
</table> </table>
{{--{{ $groups->links() }}--}} {{ $roles->links() }}
</div> </div>
<!-- /.box-body --> <!-- /.box-body -->
</div> </div>
...@@ -93,5 +90,5 @@ ...@@ -93,5 +90,5 @@
</div> </div>
<!-- /.row --> <!-- /.row -->
</section> </section>
{{--@endif--}} @endif
@endsection @endsection
\ No newline at end of file
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
</a> </a>
<ul class="treeview-menu"> <ul class="treeview-menu">
<li><a href="{{url('auth/getAll')}}">权限列表</a></li> <li><a href="{{url('auth/getAll')}}">权限列表</a></li>
<li><a href="{{url('auth/add')}}">新增权限</a></li>
{{--<li><a href="#">Link in level 2</a></li>--}} {{--<li><a href="#">Link in level 2</a></li>--}}
</ul> </ul>
......
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
<label for="email" class="col-md-4 control-label">E-Mail Address</label> <label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6"> <div class="col-md-6">
{{--<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>--}} <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
<input id="email" type="text" class="form-control" name="phone" value="{{ old('phone') }}" required autofocus>
@if ($errors->has('email')) @if ($errors->has('email'))
<span class="help-block"> <span class="help-block">
......
...@@ -81,7 +81,8 @@ Route::group(['prefix'=> 'project'],function (){ ...@@ -81,7 +81,8 @@ Route::group(['prefix'=> 'project'],function (){
// 权限 // 权限
Route::group(['prefix'=> 'auth'],function (){ Route::group(['prefix'=> 'auth'],function (){
Route::get('getAll','AuthController@getAll')->name('auth.getAll'); Route::get('getAll','AuthController@getAll')->name('auth.getAll');
Route::get('add','AuthController@add')->name('auth.add');
}); });
...@@ -101,3 +102,7 @@ Route::get('table',function (){ ...@@ -101,3 +102,7 @@ Route::get('table',function (){
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment