Skip to content
This repository was archived by the owner on Oct 15, 2023. It is now read-only.

Commit 993b449

Browse files
permission add ui
1 parent 478aa36 commit 993b449

File tree

13 files changed

+150
-21
lines changed

13 files changed

+150
-21
lines changed

app/Http/Controllers/Backend/Admin/PermissionsController.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
use Illuminate\Http\Request;
66
use App\Http\Controllers\Controller;
7-
use App\Models\Permission;
7+
use App\Http\Requests\{StorePermission, UpdatePermission};
8+
use App\Models\{Role, Permission};
89
use Yajra\DataTables\DataTables;
910

1011
class PermissionsController extends Controller
@@ -23,4 +24,26 @@ public function index(Request $request)
2324

2425
return view('backend.admin.permissions.index');
2526
}
27+
28+
public function create()
29+
{
30+
$guards = config('custom_guards.default');
31+
return view('backend.admin.permissions.create', compact('guards'));
32+
}
33+
34+
public function store(StorePermission $request)
35+
{
36+
$guards = array_intersect(array_values(config('custom_guards.default')), $request->guards ?? []);
37+
if(! count($guards)) {
38+
return back()->with('error', 'Please choose valid guard.')->withInput();
39+
}
40+
41+
foreach($guards as $each_guard) {
42+
Permission::firstOrCreate([
43+
'name' => $request->name,
44+
'guard_name' => $each_guard
45+
]);
46+
}
47+
return redirect()->route('admin.permissions.index')->with('success', 'New Permission Successfully Created.');
48+
}
2649
}

app/Http/Controllers/Backend/Admin/RolesController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function store(StoreRole $request)
6464
$created->syncPermissions($request->permissions);
6565
return redirect(config('app.prefix_admin_url') . '/admin/roles?guard=' . $request->guard)->with('success', 'New Role Successfully Created.');
6666
}
67-
return back()->withErrors(['error' => 'New Role Create Failed !'])->withInput();
67+
return back()->with('error', 'New Role Create Failed !')->withInput();
6868
}
6969

7070
/**
@@ -106,7 +106,7 @@ public function update(UpdateRole $request, Role $role)
106106
$role->syncPermissions($request->permissions);
107107
return redirect(config('app.prefix_admin_url') . '/admin/roles?guard=' . $request->guard)->with('success', 'Successfully Updated.');
108108
}
109-
return back()->withErrors(['error' => 'Role Update Failed !'])->withInput();
109+
return back()->with('error', 'Role Update Failed !')->withInput();
110110
}
111111

112112
/**

app/Http/Requests/StorePermission.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class StorePermission extends FormRequest
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*
12+
* @return bool
13+
*/
14+
public function authorize()
15+
{
16+
return true;
17+
}
18+
19+
/**
20+
* Get the validation rules that apply to the request.
21+
*
22+
* @return array
23+
*/
24+
public function rules()
25+
{
26+
return [
27+
'name' => 'required|string|max:160'
28+
];
29+
}
30+
}

config/custom_admin_permissions.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
return [
44
'default' => [
5-
'view_all_users',
6-
'add_user',
7-
'edit_user',
8-
'delete_user',
9-
'clear_user_all_data',
5+
'view users',
6+
'add user',
7+
'edit user',
8+
'delete user',
9+
'view roles',
10+
'add role',
11+
'edit role',
12+
'delete role',
1013
],
1114
];

database/seeds/SuperAdminSeeder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SuperAdminSeeder extends Seeder
1414
*/
1515
public function run()
1616
{
17-
$created = AdminUser::create([
17+
$created = AdminUser::firstOrCreate([
1818
'name' => 'Super Admin',
1919
'email' => 'admin_' . Str::slug(Str::lower(config('app.name')), '_') . '@gmail.com',
2020
'password' => Hash::make('password')

resources/views/backend/admin/admin_users/edit.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<div class="row">
5454
<div class="col-md-12 text-center">
5555
<a href="{{ route('admin.admin-users.index') }}" class="btn btn-danger mr-5">Cancel</a>
56-
<input type="submit" value="Create" class="btn btn-success">
56+
<input type="submit" value="Update" class="btn btn-success">
5757
</div>
5858
</div>
5959

resources/views/backend/admin/client_users/edit.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<div class="row">
5454
<div class="col-md-12 text-center">
5555
<a href="{{ route('admin.client-users.index') }}" class="btn btn-danger mr-5">Cancel</a>
56-
<input type="submit" value="Create" class="btn btn-success">
56+
<input type="submit" value="Update" class="btn btn-success">
5757
</div>
5858
</div>
5959

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
@extends('backend.admin.layouts.app')
2+
3+
@section('meta_title', 'Add Permission')
4+
@section('page_title', 'Add Permission')
5+
@section('page_title_icon')
6+
<i class="metismenu-icon pe-7s-lock"></i>
7+
@endsection
8+
9+
@section('content')
10+
11+
<div class="row">
12+
<div class="col-md-12">
13+
<div class="main-card mb-3 card">
14+
<div class="card-body">
15+
<form action="{{ route('admin.permissions.store') }}" method="post" id="form">
16+
@csrf
17+
<div class="row">
18+
<div class="col-md-6">
19+
<div class="form-group">
20+
<label for="name">Name</label>
21+
<input type="text" name="name" id="name" class="form-control" value="{{old('name')}}">
22+
</div>
23+
</div>
24+
25+
<div class="col-md-6">
26+
<div class="form-group">
27+
<label for="guards">Guard</label>
28+
<select class="form-control select2" name="guards[]" id="guards" multiple>
29+
@foreach($guards as $guard_alias => $guard_name)
30+
<option value="{{$guard_name}}">{{$guard_alias}} ({{$guard_name}})</option>
31+
@endforeach
32+
</select>
33+
</div>
34+
</div>
35+
</div>
36+
37+
<div class="row">
38+
<div class="col-md-12 text-center">
39+
<a href="{{ route('admin.permissions.index') }}" class="btn btn-danger mr-5">Cancel</a>
40+
<input type="submit" value="Add" class="btn btn-success">
41+
</div>
42+
</div>
43+
</form>
44+
</div>
45+
</div>
46+
</div>
47+
</div>
48+
49+
@endsection
50+
51+
@section('script')
52+
{!! JsValidator::formRequest('App\Http\Requests\StorePermission', '#form') !!}
53+
@endsection

resources/views/backend/admin/permissions/index.blade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
<i class="metismenu-icon pe-7s-door-lock"></i>
77
@endsection
88

9+
@section('page_title_buttons')
10+
<div class="d-flex justify-content-end">
11+
{{-- @can('add_permission') --}}
12+
<a href="{{route('admin.permissions.create')}}" title="Add Permission" class="btn btn-primary action-btn">Add Permission</a>
13+
{{-- @endcan --}}
14+
</div>
15+
@endsection
16+
917
@section('content')
1018

1119
<div class="row">

resources/views/backend/admin/roles/create.blade.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,23 @@
3434
<div class="col-md-12">
3535
<div class="form-group">
3636
<label for="" class="d-block">Permissions</label>
37+
<div class="row">
3738
@forelse($permissions as $permission)
38-
<div class="form-check form-check-inline mt-2">
39-
<div class="chiller_cb">
40-
<input id="{{$permission->name}}" type="checkbox" name="permissions[]" value="{{$permission->name}}" />
41-
<label for="{{$permission->name}}" class="h6">{{$permission->name}}</label>
42-
<span></span>
39+
<div class="col-md-3">
40+
<div class="form-check form-check-inline mt-2">
41+
<div class="chiller_cb">
42+
<input id="{{$permission->name}}" type="checkbox" name="permissions[]" value="{{$permission->name}}" />
43+
<label for="{{$permission->name}}" class="h6">{{$permission->name}}</label>
44+
<span></span>
45+
</div>
46+
</div>
4347
</div>
44-
</div>
4548
@empty
46-
<p class="text text-danger">No Permission Found.</p>
49+
<div class="col-md-12">
50+
<p class="text text-danger">No Permission Found.</p>
51+
</div>
4752
@endforelse
53+
</div>
4854
</div>
4955
</div>
5056
</div>

0 commit comments

Comments
 (0)