PermissionController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use App\User;
  7. use App\Models\Role;
  8. use App\Models\Permission;
  9. use Validator;
  10. class PermissionController extends Controller
  11. {
  12. public function index(){
  13. $data['title1'] = "Permission List";
  14. $data['title2'] = "Permission Add";
  15. $data['all_permissions'] = Permission::orderBy('name','ASC')->get();
  16. return view('admin.permission.index',$data);
  17. }
  18. public function store(Request $request){
  19. $this->validate($request,[
  20. 'name' => 'required|unique:permissions,name',
  21. 'display_name' => 'required',
  22. ]);
  23. $permission = new Permission();
  24. $permission->name = $request->name;
  25. $permission->display_name = $request->display_name;
  26. $permission->save();
  27. return back()->with('msg','Data Insert Successful !');
  28. }
  29. public function edit($id){
  30. $data['title'] = "Permission Edit";
  31. $data['permissions'] = Permission::find($id);
  32. return view('admin.permission.edit',$data);
  33. }
  34. public function update(Request $request,$id){
  35. $this->validate($request,[
  36. 'name' => 'required',
  37. 'display_name' => 'required',
  38. ]);
  39. $permission =Permission::find($id);
  40. $permission->name = $request->name;
  41. $permission->display_name = $request->display_name;
  42. $permission->update();
  43. return redirect('admin/permissions')->with('msg','Data Update Successful !');
  44. }
  45. public function destroy($id){
  46. Permission::whereId($id)->delete();
  47. return back()->with('msg','Data Delete Successful !');
  48. }
  49. }