// For All functions in the controller:
public function __construct(){
$this->middleware('middleware_name');
}
// Or for only some of them:
public function __construct(){
$this->middleware('middleware_name',['only' =>['create','store','edit','update']]);
}
// Or except some of them:
public function __construct(){
$this->middleware('middleware_name',['except' =>['index','show']]);
}

Making a middleware:

Let’s make a middleware “isActivated” that will check the if the user has activated his account or not (Assuming that we have a Boolean column “is_activated” in our users table):

First, we will make a middleware named “IsActivated” by running this command:

As we can see, this function will check the current user row in database and search for “is_activated” column, if it’s not equal to 1 (you can use this instead: “!($activated)” ) and then return an error message if failed or proceed to the next request.

After that, we will go to “app/Http/Kernel.php” and add our middleware to the “ $routeMiddleware” array (Note: You can see some useful middlewares there that you can use in your app):