后台管理-权限-角色管理

This commit is contained in:
fthvgb1 2018-06-02 16:28:28 +08:00
parent 6ed372954e
commit 2746e952af
10 changed files with 1068 additions and 640 deletions

View File

@ -8,4 +8,12 @@ class PagesController extends Controller
{
return view('layouts.root');
}
public function permissionDenied()
{
if (config('administrator.permission')) {
return redirect(url(config('administrator.uri')), 302);
}
return view('pages.permission_denied');
}
}

View File

@ -76,17 +76,25 @@ class TopicsController extends Controller
public function update(TopicRequest $request, Topic $topic)
{
$this->authorize('update', $topic);
$topic->update($request->all());
try {
$this->authorize('update', $topic);
$topic->update($request->all());
} catch (\Exception $exception) {
echo $exception->getMessage();
}
return redirect()->route('topics.show', [$topic->id, $topic->slug])->with('success', '编辑成功!');
}
public function destroy(Topic $topic)
{
$this->authorize('destroy', $topic);
$topic->delete();
try {
$this->authorize('destroy', $topic);
$topic->delete();
} catch (\Exception $exception) {
echo $exception->getMessage();
}
return redirect()->route('topics.index')->with('message', '删除成功.');
}
}

589
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -117,7 +117,7 @@ return array(
*
* @type string
*/
'login_path' => 'login',
'login_path' => 'permission-denied',
/**
* The logout path is the path where Administrator will send the user when they click the logout link
@ -148,4 +148,6 @@ return array(
'locales' => [],
'custom_routes_file' => app_path('Http/routes/administrator.php'),
);

View File

@ -0,0 +1,72 @@
<?php
/**
* Created by PhpStorm.
* User: xing
* Date: 2018/6/2
* Time: 16:17
*/
use Spatie\Permission\Models\Permission;
return [
'title' => '权限',
'single' => '权限',
'model' => Permission::class,
'permission' => function () {
return Auth::user()->can('manage_users');
},
// 对 CRUD 动作的单独权限控制,通过返回布尔值来控制权限。
'action_permissions' => [
// 控制『新建按钮』的显示
'create' => function ($model) {
return true;
},
// 允许更新
'update' => function ($model) {
return true;
},
// 不允许删除
'delete' => function ($model) {
return false;
},
// 允许查看
'view' => function ($model) {
return true;
},
],
'columns' => [
'id' => [
'title' => 'ID',
],
'name' => [
'title' => '标示',
],
'operation' => [
'title' => '管理',
'sortable' => false,
],
],
'edit_fields' => [
'name' => [
'title' => '标示(请慎重修改)',
// 表单条目标题旁的『提示信息』
'hint' => '修改权限标识会影响代码的调用,请不要轻易更改。'
],
'roles' => [
'type' => 'relationship',
'title' => '角色',
'name_field' => 'name',
],
],
'filters' => [
'name' => [
'title' => '标示',
],
],
];

View File

@ -0,0 +1,79 @@
<?php
/**
* Created by PhpStorm.
* User: xing
* Date: 2018/6/2
* Time: 16:08
*/
use Spatie\Permission\Models\Role;
return [
'title' => '角色',
'single' => '角色',
'model' => Role::class,
'permission' => function () {
return Auth::user()->can('manage_users');
},
'columns' => [
'id' => [
'title' => 'ID',
],
'name' => [
'title' => '标识'
],
'permissions' => [
'title' => '权限',
'output' => function ($value, $model) {
$model->load('permissions');
$result = [];
foreach ($model->permissions as $permission) {
$result[] = $permission->name;
}
return empty($result) ? 'N/A' : implode($result, ' | ');
},
'sortable' => false,
],
'operation' => [
'title' => '管理',
'output' => function ($value, $model) {
return $value;
},
'sortable' => false,
],
],
'edit_fields' => [
'name' => [
'title' => '标识',
],
'permissions' => [
'type' => 'relationship',
'title' => '权限',
'name_field' => 'name',
],
],
'filters' => [
'id' => [
'title' => 'ID',
],
'name' => [
'title' => '标识',
]
],
// 新建和编辑时的表单验证规则
'rules' => [
'name' => 'required|max:15|unique:roles,name',
],
// 表单验证错误时定制错误消息
'messages' => [
'name.required' => '标识不能为空',
'name.unique' => '标识已存在',
]
];

902
public/js/app.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
@extends('layouts.app')
@section('title','无权限访问')
@section('content')
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-body">
@if (Auth::check())
<div class="alert alert-danger text-center">
当前登录账号无后台访问权限。
</div>
@else
<div class="alert alert-danger text-center">
请登录以后再操作
</div>
<a class="btn btn-lg btn-primary btn-block" href="{{ route('login') }}">
<span class="glyphicon glyphicon-log-in" aria-hidden="true"></span>
</a>
@endif
</div>
</div>
</div>
@endsection

View File

@ -39,4 +39,6 @@ Route::post('upload_image', 'TopicsController@uploadImage')->name('topics.upload
Route::resource('replies', 'RepliesController', ['only' => ['store', 'destroy']]);
Route::resource('notifications', 'NotificationsController', ['only' => ['index']])->middleware('auth');
Route::resource('notifications', 'NotificationsController', ['only' => ['index']])->middleware('auth');
Route::get('permission-denied', 'PagesController@permissionDenied')->name('permission-denied');

View File

@ -0,0 +1,6 @@
{
"site_name": "larabbs - Powered by LaraBBS",
"contact_email": "fthvgb1@163.com",
"seo_description": "laravel\u642d\u5efa\u7684bbs",
"seo_keyword": "laravel,bbs,laravel\u793e\u533a"
}