Purchase access to watch this video.

Unlock course for £159

Already purchased access? Login

Wrapping up and next steps

  1. Let's start wrapping things up.
  2. Earlier in the course, we created routes to allow users to upload video files,
  3. but currently this is still open to any user.
  4. Let's restrict this to just administrator users only.
  5. We first need a way to actually identify administrators.
  6. The simplest method is to just add a column to our "users" table.
  7. Let's create new migration.
  8. It's a good idea to be as descriptive and literal with migration names as
  9. possible.
  10. We're going to add an "is_admin" column to the "users" table,
  11. so let's name the migration as such.
  12. [typing sounds]
  13. Open it up and add a new boolean type column with a default value.
  14. Of "false".
  15. [typing sounds]
  16. Open up your User model and add a cast for this new column.
  17. [typing sounds]
  18. Run artisan migrate to migrate the database with the new migration.
  19. We're going to create middleware to check if the authenticated user is an
  20. administrator or not.
  21. So let's create a new middleware class.
  22. [typing sounds]
  23. Open it up.
  24. Inside this middleware, we can check for the user on the request
  25. and see if their "is_admin" column value is "true" or not.
  26. If it is, they're an administrator and the request should continue.
  27. If not, we need to throw an appropriate error.
  28. We'll throw a 403 Forbidden error as the user is authenticated
  29. but does not have permission to execute the request.
  30. [typing sounds]
  31. For ease, we can add a new middleware to the HTTP kernel and register it with a
  32. nicer, shorter name.
  33. Open up your HTTP kernel file.
  34. And in the aliases array, add a key for "admin".
  35. And use our new class name.
  36. Open up your routes web file and you'll notice our administration routes are
  37. conveniently grouped already.
  38. And that group itself is within a route group with the "auth" middleware applied.
  39. Therefore, we just need to add our new "admin" middleware to this group.
  40. If we now try to go to any of our administration routes such as one to upload
  41. videos,
  42. we'll be greeted with a 403 Forbidden response.
  43. We can test if our middleware's working is intended by making our user account
  44. an administrator.
  45. Open up your database and go to the "users" table.
  46. And for the row for your user account, set the "is_admin" column to "1".
  47. And now if we refresh the upload video page, we should be able to see it this
  48. time.
  49. In our upload URL controller
  50. you may remember that we were creating test mode videos only.
  51. This creates videos that are maximum of 10 seconds long, watermarked, deleted
  52. after 24 hours,
  53. and do not incur a charge from Mux.
  54. However, when you go live, you probably do want to upload full length videos
  55. and without a Mux watermark.
  56. Instead of hard-coding this test parameter to "true", we can make it configurable.
  57. Let's replace it with a configuration key.
  58. Open up your config/services.php file and add that key.
  59. Make its default value a "MUX_TEST" environment variable.
  60. And let's give it a default value of "true" and cast it as a boolean.
  61. Let's take this "MUX_TEST" value.
  62. And add it as a key in our .env file.
  63. Again, set its default value to "true", and also copy it to your .env.example file.
  64. We'll leave the value as "true" as its a sensible default.
  65. So now test mode is true by default, but can be overridden by a "MUX_TEST"
  66. environment variable.
  67. So when you do go live, you want to make sure that you have set a "MUX_TEST"
  68. environment variable
  69. and its value is set to "false".
  70. So far, we've been working with separate home and dashboard routes for the sole
  71. reason that's what Breeze gave us out of the box.
  72. But we don't have an application where users should see different views
  73. depending on if they're logged in or not.
  74. Users should see the videos list regardless.
  75. We can use the videos index view as our home view.
  76. So first let's change the main navigation bar.
  77. Open up your layouts/navigation partial.
  78. Find the dashboard link and change its name to "videos".
  79. Let's change the href to "videos.index".
  80. Open up your routes/web.php file.
  81. Delete the existing "home" route and "dashboard" route.
  82. And we're going to add two new redirects, just redirecting to the videos index.
  83. Now if we're go and refresh our homepage, we should be redirected to our
  84. videos index.
  85. And that just about wraps things up.
  86. We now have a website where we can upload videos, where customers can subscribe
  87. to watch these videos, and where analytical data about the videos being watched
  88. is being recorded.
  89. As next steps, you can build on the functionality we've already created and add
  90. new features.
  91. Maybe add the ability for users to create playlists of videos or to collect
  92. videos in collections.
  93. If this were a site like Netflix or Amazon Prime Video, you may have
  94. collections for action, comedy, and so on,
  95. or even seasonal and topical collections such as Christmas movies or royal
  96. dramas if your country has just crowned a new monarch.
  97. Do let me know what you end up building and I hope you enjoy this course and
  98. learned a lot along the way.
Connect GitHub