Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
WEBVTT
00:01.240 --> 00:05.740
In this lecture, I will introduce the concept of middleware.
00:06.670 --> 00:17.170
So in simplest terms, the middleware is the code that runs before and after the controller, an example
00:17.180 --> 00:25.150
job of before middleware is to limit access to only the authenticated users.
00:26.080 --> 00:34.420
Now, the example job of after middleware is to add some headers to the response.
00:38.070 --> 00:45.270
You can create your own middleware, though, it's also heavily used internally by Laravel to supply
00:45.270 --> 00:55.800
typical functionality, middleware is a piece B class and it has to have at least one method called
00:55.800 --> 00:56.430
handle.
00:57.120 --> 01:01.210
It does not have to extend any base, class or interface.
01:01.920 --> 01:11.550
These are two minimal examples of an before and after model where the perform action command is, where
01:11.580 --> 01:18.140
you'd put some extra logic if you really want to understand how to make your own middleware.
01:18.700 --> 01:24.090
It's a good idea to look at existing middleware provided with Laravel.
01:25.640 --> 01:34.850
There are three levels of applying middleware first, global essential middleware is applied on all
01:34.850 --> 01:36.110
routes always.
01:37.300 --> 01:48.700
Secondly, some is applied only in Web and API routes, all of above is configurable in the kernel file,
01:48.700 --> 01:59.500
which will take a look at in a second third level, Eastern were applied per route groups per controller
01:59.500 --> 02:00.100
class.
02:00.640 --> 02:06.510
You will learn about control classes in a bid or per individual route.
02:08.360 --> 02:14.510
Let's take a look at the colonel file, which can be found inside the app HTP folder.
02:16.870 --> 02:21.670
The middleware field defines their globally applied middleware.
02:23.520 --> 02:30.990
The middle where groups feel that defined the Web and API roots specific middleware.
02:35.000 --> 02:39.590
One of the root object methods is middleware.
02:40.660 --> 02:49.150
That way, you can apply to a group of roots or a specific route now to make it a little bit easier.
02:49.210 --> 02:54.640
You don't have to use a full class name like you've seen in the colonel file.
02:55.820 --> 03:05.870
In this colonel be filed, there is another field called Route Middleware, and it defines a thing called
03:05.870 --> 03:07.310
analysis.
03:08.240 --> 03:18.260
Now using this Elias's, you can easily apply middleware using the middleware method and passing those.
03:18.260 --> 03:22.040
Elias's using a comma separated string.
03:23.310 --> 03:31.980
For example, if I would use that Alpha Middleware on this specific route from now on, it would require
03:31.980 --> 03:35.490
the user to be authenticated to visit this route.
03:36.930 --> 03:45.360
Now, the middleware also can accept parameters and we will use it later when we cover the user authorization.
03:46.800 --> 03:52.030
Finally, let's verify if the S middleware was properly applied on this route.
03:52.740 --> 03:55.500
So currently the route looks like this.
03:55.770 --> 04:02.700
After refreshing this page, I should see some kind of error because we have no concept of authentication
04:02.700 --> 04:04.220
in our application yet.
04:05.340 --> 04:08.730
And indeed, after refreshing, you see an error.
04:11.180 --> 04:17.120
There is nothing to worry about when you will learn about authentication in Laravel, this error would
04:17.120 --> 04:18.600
just simply go away.
3579
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.