Wrapping up and next steps
Transcript was automatically generated and may be inaccurate.
-
–
Let's start wrapping things up. -
–
Earlier in the course, we created routes to allow users to upload video files, -
–
but currently this is still open to any user. -
–
Let's restrict this to just administrator users only. -
–
We first need a way to actually identify administrators. -
–
The simplest method is to just add a column to our "users" table. -
–
Let's create new migration. -
–
It's a good idea to be as descriptive and literal with migration names as -
–
possible. -
–
We're going to add an "is_admin" column to the "users" table, -
–
so let's name the migration as such. -
–
[typing sounds] -
–
Open it up and add a new boolean type column with a default value. -
–
Of "false". -
–
[typing sounds] -
–
Open up your User model and add a cast for this new column. -
–
[typing sounds] -
–
Run artisan migrate to migrate the database with the new migration. -
–
We're going to create middleware to check if the authenticated user is an -
–
administrator or not. -
–
So let's create a new middleware class. -
–
[typing sounds] -
–
Open it up. -
–
Inside this middleware, we can check for the user on the request -
–
and see if their "is_admin" column value is "true" or not. -
–
If it is, they're an administrator and the request should continue. -
–
If not, we need to throw an appropriate error. -
–
We'll throw a 403 Forbidden error as the user is authenticated -
–
but does not have permission to execute the request. -
–
[typing sounds] -
–
For ease, we can add a new middleware to the HTTP kernel and register it with a -
–
nicer, shorter name. -
–
Open up your HTTP kernel file. -
–
And in the aliases array, add a key for "admin". -
–
And use our new class name. -
–
Open up your routes web file and you'll notice our administration routes are -
–
conveniently grouped already. -
–
And that group itself is within a route group with the "auth" middleware applied. -
–
Therefore, we just need to add our new "admin" middleware to this group. -
–
If we now try to go to any of our administration routes such as one to upload -
–
videos, -
–
we'll be greeted with a 403 Forbidden response. -
–
We can test if our middleware's working is intended by making our user account -
–
an administrator. -
–
Open up your database and go to the "users" table. -
–
And for the row for your user account, set the "is_admin" column to "1". -
–
And now if we refresh the upload video page, we should be able to see it this -
–
time. -
–
In our upload URL controller -
–
you may remember that we were creating test mode videos only. -
–
This creates videos that are maximum of 10 seconds long, watermarked, deleted -
–
after 24 hours, -
–
and do not incur a charge from Mux. -
–
However, when you go live, you probably do want to upload full length videos -
–
and without a Mux watermark. -
–
Instead of hard-coding this test parameter to "true", we can make it configurable. -
–
Let's replace it with a configuration key. -
–
Open up your config/services.php file and add that key. -
–
Make its default value a "MUX_TEST" environment variable. -
–
And let's give it a default value of "true" and cast it as a boolean. -
–
Let's take this "MUX_TEST" value. -
–
And add it as a key in our .env file. -
–
Again, set its default value to "true", and also copy it to your .env.example file. -
–
We'll leave the value as "true" as its a sensible default. -
–
So now test mode is true by default, but can be overridden by a "MUX_TEST" -
–
environment variable. -
–
So when you do go live, you want to make sure that you have set a "MUX_TEST" -
–
environment variable -
–
and its value is set to "false". -
–
So far, we've been working with separate home and dashboard routes for the sole -
–
reason that's what Breeze gave us out of the box. -
–
But we don't have an application where users should see different views -
–
depending on if they're logged in or not. -
–
Users should see the videos list regardless. -
–
We can use the videos index view as our home view. -
–
So first let's change the main navigation bar. -
–
Open up your layouts/navigation partial. -
–
Find the dashboard link and change its name to "videos". -
–
Let's change the href to "videos.index". -
–
Open up your routes/web.php file. -
–
Delete the existing "home" route and "dashboard" route. -
–
And we're going to add two new redirects, just redirecting to the videos index. -
–
Now if we're go and refresh our homepage, we should be redirected to our -
–
videos index. -
–
And that just about wraps things up. -
–
We now have a website where we can upload videos, where customers can subscribe -
–
to watch these videos, and where analytical data about the videos being watched -
–
is being recorded. -
–
As next steps, you can build on the functionality we've already created and add -
–
new features. -
–
Maybe add the ability for users to create playlists of videos or to collect -
–
videos in collections. -
–
If this were a site like Netflix or Amazon Prime Video, you may have -
–
collections for action, comedy, and so on, -
–
or even seasonal and topical collections such as Christmas movies or royal -
–
dramas if your country has just crowned a new monarch. -
–
Do let me know what you end up building and I hope you enjoy this course and -
–
learned a lot along the way.