|
15 | 15 |
|
16 | 16 | class PermissionController extends Controller |
17 | 17 | { |
18 | | - /** |
19 | | - * Display a listing of the resource. |
20 | | - * @return \Illuminate\Http\Response |
21 | | - */ |
22 | | - public function index() |
23 | | - { |
24 | | - return view('backend.admin.permission.index'); |
25 | | - } |
26 | | - |
27 | | - public function getAll() |
28 | | - { |
29 | | - $can_edit = $can_delete = ''; |
30 | | - if (!auth()->user()->can('permission-edit')) { |
31 | | - $can_edit = "style='display:none;'"; |
32 | | - } |
33 | | - if (!auth()->user()->can('permission-delete')) { |
34 | | - $can_delete = "style='display:none;'"; |
35 | | - } |
36 | | - |
37 | | - $usepermission = UserPermission::get(); |
38 | | - return Datatables::of($usepermission) |
39 | | - ->addColumn('action', function ($usepermission) use ($can_edit, $can_delete) { |
40 | | - $html = '<div class="btn-group">'; |
41 | | - $html .= '<a data-toggle="tooltip" ' . $can_edit . ' id="' . $usepermission->id . '" class="btn btn-xs btn-info mr-1 edit" title="Edit"><i class="fa fa-edit"></i> </a>'; |
42 | | - // $html .= '<a data-toggle="tooltip" ' . $can_delete . ' id="' . $usepermission->id . '" class="btn btn-xs btn-danger mr-1 delete" title="Delete"><i class="fa fa-trash"></i> </a>'; |
43 | | - $html .= '</div>'; |
44 | | - return $html; |
45 | | - }) |
46 | | - ->rawColumns(['action']) |
47 | | - ->addIndexColumn() |
48 | | - ->make(true); |
49 | | - } |
50 | | - |
51 | | - /** |
52 | | - * Show the form for creating a new resource. |
53 | | - * @return \Illuminate\Http\Response |
54 | | - */ |
55 | | - public function create(Request $request) |
56 | | - { |
57 | | - if ($request->ajax()) { |
58 | | - $haspermision = auth()->user()->can('permission-create'); |
59 | | - if ($haspermision) { |
60 | | - $view = View::make('backend.admin.permission.create')->render(); |
61 | | - return response()->json(['html' => $view]); |
62 | | - } else { |
63 | | - abort(403, 'Sorry, you are not authorized to access the page'); |
64 | | - } |
65 | | - } else { |
66 | | - return response()->json(['status' => 'false', 'message' => "Access only ajax request"]); |
67 | | - } |
68 | | - } |
69 | | - |
70 | | - /** |
71 | | - * Store a newly created resource in storage. |
72 | | - * |
73 | | - * @param \Illuminate\Http\Request $request |
74 | | - * |
75 | | - * @return \Illuminate\Http\Response |
76 | | - */ |
77 | | - public function store(Request $request) |
78 | | - { |
79 | | - |
80 | | - if ($request->ajax()) { |
81 | | - // Setup the validator |
82 | | - $rules = [ |
83 | | - 'name' => 'required|unique:permissions' |
84 | | - ]; |
85 | | - |
86 | | - $validator = Validator::make($request->all(), $rules); |
87 | | - if ($validator->fails()) { |
88 | | - return response()->json([ |
89 | | - 'type' => 'error', |
90 | | - 'errors' => $validator->getMessageBag()->toArray() |
91 | | - ]); |
92 | | - } else { |
93 | | - Permission::findOrCreate($request->name); |
94 | | - return response()->json(['type' => 'success', 'message' => "Successfully Created"]); |
95 | | - } |
96 | | - } else { |
97 | | - return response()->json(['status' => 'false', 'message' => "Access only ajax request"]); |
98 | | - } |
99 | | - |
100 | | - } |
101 | | - |
102 | | - /** |
103 | | - * Display the specified resource. |
104 | | - * |
105 | | - * @param int $id |
106 | | - * |
107 | | - * @return \Illuminate\Http\Response |
108 | | - */ |
109 | | - public function show(Request $request, Permission $permission) |
110 | | - { |
111 | | - if ($request->ajax()) { |
112 | | - |
113 | | - } else { |
114 | | - return response()->json(['status' => 'false', 'message' => "Access only ajax request"]); |
115 | | - } |
116 | | - } |
117 | | - |
118 | | - /** |
119 | | - * Show the form for editing the specified resource. |
120 | | - * |
121 | | - * @param int $id |
122 | | - * |
123 | | - * @return \Illuminate\Http\Response |
124 | | - */ |
125 | | - public function edit(Request $request, Permission $permission) |
126 | | - { |
127 | | - if ($request->ajax()) { |
128 | | - $haspermision = auth()->user()->can('permission-edit'); |
129 | | - if ($haspermision) { |
130 | | - $view = View::make('backend.admin.permission.edit', compact('permission'))->render(); |
131 | | - return response()->json(['html' => $view]); |
132 | | - } else { |
133 | | - abort(403, 'Sorry, you are not authorized to access the page'); |
134 | | - } |
135 | | - } else { |
136 | | - return response()->json(['status' => 'false', 'message' => "Access only ajax request"]); |
137 | | - } |
138 | | - } |
139 | | - |
140 | | - /** |
141 | | - * Update the specified resource in storage. |
142 | | - * |
143 | | - * @param \Illuminate\Http\Request $request |
144 | | - * @param int $id |
145 | | - * |
146 | | - * @return \Illuminate\Http\Response |
147 | | - */ |
148 | | - public function update(Request $request, Permission $permission) |
149 | | - { |
150 | | - if ($request->ajax()) { |
151 | | - // Setup the validator |
152 | | - Permission::findOrFail($permission->id); |
153 | | - |
154 | | - $rules = [ |
155 | | - 'name' => 'required|unique:permissions,name,' . $permission->id |
156 | | - ]; |
157 | | - |
158 | | - $validator = Validator::make($request->all(), $rules); |
159 | | - if ($validator->fails()) { |
160 | | - return response()->json([ |
161 | | - 'type' => 'error', |
162 | | - 'errors' => $validator->getMessageBag()->toArray() |
163 | | - ]); |
164 | | - } else { |
165 | | - $permission->name = $request->name; |
166 | | - $permission->save(); |
167 | | - return response()->json(['type' => 'success', 'message' => "Successfully Updated"]); |
168 | | - } |
169 | | - } else { |
170 | | - return response()->json(['status' => 'false', 'message' => "Access only ajax request"]); |
171 | | - } |
172 | | - } |
173 | | - |
174 | | - /** |
175 | | - * Remove the specified resource from storage. |
176 | | - * |
177 | | - * @param int $id |
178 | | - * |
179 | | - * @return \Illuminate\Http\Response |
180 | | - */ |
181 | | - public function destroy($id) |
182 | | - { |
183 | | - // |
184 | | - } |
| 18 | + /** |
| 19 | + * Display a listing of the resource. |
| 20 | + * @return \Illuminate\Http\Response |
| 21 | + */ |
| 22 | + public function index() |
| 23 | + { |
| 24 | + return view('backend.admin.permission.index'); |
| 25 | + } |
| 26 | + |
| 27 | + public function getAll() |
| 28 | + { |
| 29 | + $can_edit = $can_delete = ''; |
| 30 | + if (!auth()->user()->can('permission-edit')) { |
| 31 | + $can_edit = "style='display:none;'"; |
| 32 | + } |
| 33 | + if (!auth()->user()->can('permission-delete')) { |
| 34 | + $can_delete = "style='display:none;'"; |
| 35 | + } |
| 36 | + |
| 37 | + $usepermission = UserPermission::where('guard_name', 'user')->get(); |
| 38 | + return Datatables::of($usepermission) |
| 39 | + ->addColumn('action', function ($usepermission) use ($can_edit, $can_delete) { |
| 40 | + $html = '<div class="btn-group">'; |
| 41 | + $html .= '<a data-toggle="tooltip" ' . $can_edit . ' id="' . $usepermission->id . '" class="btn btn-xs btn-info mr-1 edit" title="Edit"><i class="fa fa-edit"></i> </a>'; |
| 42 | + // $html .= '<a data-toggle="tooltip" ' . $can_delete . ' id="' . $usepermission->id . '" class="btn btn-xs btn-danger mr-1 delete" title="Delete"><i class="fa fa-trash"></i> </a>'; |
| 43 | + $html .= '</div>'; |
| 44 | + return $html; |
| 45 | + }) |
| 46 | + ->rawColumns(['action']) |
| 47 | + ->addIndexColumn() |
| 48 | + ->make(true); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Show the form for creating a new resource. |
| 53 | + * @return \Illuminate\Http\Response |
| 54 | + */ |
| 55 | + public function create(Request $request) |
| 56 | + { |
| 57 | + if ($request->ajax()) { |
| 58 | + $haspermision = auth()->user()->can('permission-create'); |
| 59 | + if ($haspermision) { |
| 60 | + $view = View::make('backend.admin.permission.create')->render(); |
| 61 | + return response()->json(['html' => $view]); |
| 62 | + } else { |
| 63 | + abort(403, 'Sorry, you are not authorized to access the page'); |
| 64 | + } |
| 65 | + } else { |
| 66 | + return response()->json(['status' => 'false', 'message' => "Access only ajax request"]); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Store a newly created resource in storage. |
| 72 | + * |
| 73 | + * @param \Illuminate\Http\Request $request |
| 74 | + * |
| 75 | + * @return \Illuminate\Http\Response |
| 76 | + */ |
| 77 | + public function store(Request $request) |
| 78 | + { |
| 79 | + |
| 80 | + if ($request->ajax()) { |
| 81 | + // Setup the validator |
| 82 | + $rules = [ |
| 83 | + 'name' => 'required|unique:permissions' |
| 84 | + ]; |
| 85 | + |
| 86 | + $validator = Validator::make($request->all(), $rules); |
| 87 | + if ($validator->fails()) { |
| 88 | + return response()->json([ |
| 89 | + 'type' => 'error', |
| 90 | + 'errors' => $validator->getMessageBag()->toArray() |
| 91 | + ]); |
| 92 | + } else { |
| 93 | + Permission::Create(['guard_name' => 'user', 'name' => $request->name]); |
| 94 | + return response()->json(['type' => 'success', 'message' => "Successfully Created"]); |
| 95 | + } |
| 96 | + } else { |
| 97 | + return response()->json(['status' => 'false', 'message' => "Access only ajax request"]); |
| 98 | + } |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Display the specified resource. |
| 104 | + * |
| 105 | + * @param int $id |
| 106 | + * |
| 107 | + * @return \Illuminate\Http\Response |
| 108 | + */ |
| 109 | + public function show(Request $request, Permission $permission) |
| 110 | + { |
| 111 | + if ($request->ajax()) { |
| 112 | + |
| 113 | + } else { |
| 114 | + return response()->json(['status' => 'false', 'message' => "Access only ajax request"]); |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Show the form for editing the specified resource. |
| 120 | + * |
| 121 | + * @param int $id |
| 122 | + * |
| 123 | + * @return \Illuminate\Http\Response |
| 124 | + */ |
| 125 | + public function edit(Request $request, Permission $permission) |
| 126 | + { |
| 127 | + if ($request->ajax()) { |
| 128 | + $haspermision = auth()->user()->can('permission-edit'); |
| 129 | + if ($haspermision) { |
| 130 | + $view = View::make('backend.admin.permission.edit', compact('permission'))->render(); |
| 131 | + return response()->json(['html' => $view]); |
| 132 | + } else { |
| 133 | + abort(403, 'Sorry, you are not authorized to access the page'); |
| 134 | + } |
| 135 | + } else { |
| 136 | + return response()->json(['status' => 'false', 'message' => "Access only ajax request"]); |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Update the specified resource in storage. |
| 142 | + * |
| 143 | + * @param \Illuminate\Http\Request $request |
| 144 | + * @param int $id |
| 145 | + * |
| 146 | + * @return \Illuminate\Http\Response |
| 147 | + */ |
| 148 | + public function update(Request $request, Permission $permission) |
| 149 | + { |
| 150 | + if ($request->ajax()) { |
| 151 | + // Setup the validator |
| 152 | + Permission::findOrFail($permission->id); |
| 153 | + |
| 154 | + $rules = [ |
| 155 | + 'name' => 'required|unique:permissions,name,' . $permission->id |
| 156 | + ]; |
| 157 | + |
| 158 | + $validator = Validator::make($request->all(), $rules); |
| 159 | + if ($validator->fails()) { |
| 160 | + return response()->json([ |
| 161 | + 'type' => 'error', |
| 162 | + 'errors' => $validator->getMessageBag()->toArray() |
| 163 | + ]); |
| 164 | + } else { |
| 165 | + $permission->name = $request->name; |
| 166 | + $permission->save(); |
| 167 | + return response()->json(['type' => 'success', 'message' => "Successfully Updated"]); |
| 168 | + } |
| 169 | + } else { |
| 170 | + return response()->json(['status' => 'false', 'message' => "Access only ajax request"]); |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Remove the specified resource from storage. |
| 176 | + * |
| 177 | + * @param int $id |
| 178 | + * |
| 179 | + * @return \Illuminate\Http\Response |
| 180 | + */ |
| 181 | + public function destroy($id) |
| 182 | + { |
| 183 | + // |
| 184 | + } |
185 | 185 | } |
0 commit comments