Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel https middleware

namespace AppHttpMiddleware;

use Closure;
use IlluminateSupportFacadesApp;

class HttpsProtocolMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!$request->secure() && app()->environment('production')) {
            return redirect()->secure($request->getRequestUri());
        }

        return $next($request);
    }
}

#then in Http/Kernel

protected $middlewareGroups = [
    'web' => [
       AppHttpMiddlewareEncryptCookies::class,
       IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class,
       IlluminateSessionMiddlewareStartSession::class,
       //IlluminateSessionMiddlewareAuthenticateSession::class,
       IlluminateViewMiddlewareShareErrorsFromSession::class,
       AppHttpMiddlewareVerifyCsrfToken::class,
       IlluminateRoutingMiddlewareSubstituteBindings::class,
       AppHttpMiddlewareHttpsProtocolMiddleware::class
    ],

    'api' => [
        'throttle:60,1',
        'bindings',
    ],
];
Source by robindirksen.com #
 
PREVIOUS NEXT
Tagged: #laravel #https #middleware
ADD COMMENT
Topic
Name
9+9 =