Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppHttpControllers;
  4. use AppUser;
  5. use AppBook;
  6. use AppReview;
  7. use AppComment;
  8. use IlluminateHttpRequest;
  9. use IlluminateSupportFacadesGate;
  10.  
  11.  
  12. class AdminsController extends Controller
  13. {
  14. public function admin()
  15. {
  16. if (Gate::allows('admins', auth()->user())) {
  17. return view('admin.dashboard');
  18. }
  19. return 'Unauthorized entry';
  20. }
  21. /**
  22. * Display a listing of the resource.
  23. *
  24. * @return IlluminateHttpResponse
  25. */
  26.  
  27. public function index()
  28. {
  29. $users = User::all();
  30. $books = Book::all();
  31. $reviews = Review::all();
  32. $comments = Comment::all();
  33.  
  34.  
  35. return view('admin.dashboard', compact('users' ,'books', 'reviews', 'comments'));
  36.  
  37.  
  38. }
  39.  
  40. Gate::define('admins', function ($user) {
  41. if($user->isAdmin == 1)
  42. {
  43. return true;
  44. }
  45. return false;
  46. });
  47.  
  48. // Admin
  49. Route::resource('admin', 'AdminsController');
  50. Route::get('/admin', 'AdminsController@admin')->name('admin');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement