Skip to content

Instantly share code, notes, and snippets.

@kyleridolfo
Created September 30, 2015 19:53
Show Gist options
  • Save kyleridolfo/4e9c5f9bfa855c2bd63f to your computer and use it in GitHub Desktop.
Save kyleridolfo/4e9c5f9bfa855c2bd63f to your computer and use it in GitHub Desktop.

Revisions

  1. @nblackburn nblackburn revised this gist Jul 31, 2015. 1 changed file with 1 addition and 8 deletions.
    9 changes: 1 addition & 8 deletions Secure.php
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,6 @@

    use Closure;
    use Illuminate\Contracts\Routing\Middleware;
    use Illuminate\Contracts\Foundation\Application;

    /**
    * Secure
    @@ -14,16 +13,10 @@
    */
    class Secure implements Middleware
    {
    protected $app;

    public function __construct(Application $app)
    {
    $this->app = $app;
    }

    public function handle($request, Closure $next)
    {
    if (!$request->secure() && $this->app->environment() === 'production') {
    if (!$request->secure() && app()->environment('production')) {
    return redirect()->secure($request->getRequestUri());
    }

  2. @nblackburn nblackburn revised this gist Nov 12, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Secure.php
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@

    use Closure;
    use Illuminate\Contracts\Routing\Middleware;
    use Illuminate\Contracts\Foundation\Application;

    /**
    * Secure
  3. @nblackburn nblackburn revised this gist Nov 12, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Secure.php
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,8 @@
    * @param $next The next closure.
    * @return redirects to the secure counterpart of the requested uri.
    */
    class Secure implements Middleware {
    class Secure implements Middleware
    {
    protected $app;

    public function __construct(Application $app)
  4. @nblackburn nblackburn revised this gist Nov 12, 2014. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion Secure.php
    Original file line number Diff line number Diff line change
    @@ -13,9 +13,16 @@
    */
    class Secure implements Middleware {

    protected $app;

    public function __construct(Application $app)
    {
    $this->app = $app;
    }

    public function handle($request, Closure $next)
    {
    if (!$request->secure() && \App::environment() === 'production') {
    if (!$request->secure() && $this->app->environment() === 'production') {
    return redirect()->secure($request->getRequestUri());
    }

  5. @nblackburn nblackburn revised this gist Nov 3, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    I noticed that Laravel 5 doesn't have a secure (_https_) filter so i have re-implemented it in the form of a middleware, i hope that you find this useful.
    I noticed that Laravel 5 doesn't have a secure (_https_) middleware since the removal of filters. So i have re-implemented it and shared the code in the hope that you find it useful.

    ## Installation

    @@ -7,5 +7,5 @@ I noticed that Laravel 5 doesn't have a secure (_https_) filter so i have re-imp

    ## Notes

    - If you are using route annotations, don't forget to rescan your routes using the `php artisan route:scan` command.
    - The redirect is disabled in any non-production environment (as you likely won't have acquired a certificate at this stage).
    - If you are using route annotations, don't forget to re-scan your routes using the `php artisan route:scan` command.
    - The redirect is disabled in any non-production environment (_as you likely won't have acquired a certificate at this stage_).
  6. @nblackburn nblackburn revised this gist Nov 3, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Secure.php
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@

    /**
    * Secure
    * Redirects any non-secure links to their secure counterparts.
    * Redirects any non-secure requests to their secure counterparts.
    *
    * @param request The request object.
    * @param $next The next closure.
  7. @nblackburn nblackburn revised this gist Nov 3, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Secure.php
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@
    /**
    * Secure
    * Redirects any non-secure links to their secure counterparts.
    *
    * @param request The request object.
    * @param $next The next closure.
    * @return redirects to the secure counterpart of the requested uri.
  8. @nblackburn nblackburn revised this gist Nov 3, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions Secure.php
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,13 @@
    use Closure;
    use Illuminate\Contracts\Routing\Middleware;

    /**
    * Secure
    * Redirects any non-secure links to their secure counterparts.
    * @param request The request object.
    * @param $next The next closure.
    * @return redirects to the secure counterpart of the requested uri.
    */
    class Secure implements Middleware {

    public function handle($request, Closure $next)
  9. @nblackburn nblackburn revised this gist Nov 3, 2014. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,4 @@ I noticed that Laravel 5 doesn't have a secure (_https_) filter so i have re-imp
    ## Notes

    - If you are using route annotations, don't forget to rescan your routes using the `php artisan route:scan` command.
    - The redirect is disabled in any non-production environment (as you likely won't have acquired a certificate at this stage).

    [Gist](https://gist.github.com/nblackburn/a66e8e93561e277996aa)
    - The redirect is disabled in any non-production environment (as you likely won't have acquired a certificate at this stage).
  10. @nblackburn nblackburn revised this gist Nov 3, 2014. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,13 @@
    # Secure Middleware for Laravel 5

    I noticed that Laravel 5 doesn't have a secure (_https_) filter so i have re-implemented it in the form of a middleware, i hope that you find this useful.

    ## Installation
    ## Installation

    - Add `Secure.php` to your `app\Http\Middleware` directory.
    - Add the secure middleware to your route.

    ## Notes

    - If you are using route annotations, don't forget to rescan your routes using the `php artisan route:scan` command.
    - If you are using route annotations, don't forget to rescan your routes using the `php artisan route:scan` command.
    - The redirect is disabled in any non-production environment (as you likely won't have acquired a certificate at this stage).

    [Gist](https://gist.github.com/nblackburn/a66e8e93561e277996aa)
  11. @nblackburn nblackburn revised this gist Nov 3, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Secure Middleware for Laravel 5

    I noticed that Laravel 5 doesn't have a secure (_https_) filter so i have re-implemented it in the form of a middleware, i hope that you find this useful.

    ## Installation

    - Add `Secure.php` to your `app\Http\Middleware` directory.
  12. @nblackburn nblackburn revised this gist Nov 3, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,4 @@

    ## Notes

    If you are using route annotations, don't forget to rescan your routes using the `php artisan route:scan` command.
    - If you are using route annotations, don't forget to rescan your routes using the `php artisan route:scan` command.
  13. @nblackburn nblackburn revised this gist Nov 3, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,6 @@

    - Add `Secure.php` to your `app\Http\Middleware` directory.
    - Add the secure middleware to your route.
    - run `php artisan route:scan`.

    ## Notes

  14. @nblackburn nblackburn revised this gist Nov 3, 2014. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    # Secure Middleware for Laravel 5

    ## Installation

    - Add `Secure.php` to your `app\Http\Middleware` directory.
    - Add the secure middleware to your route`
    - run `php artisan route:scan`
    - Add the secure middleware to your route.
    - run `php artisan route:scan`.

    ## Notes

    If you are using route annotations, don't forget to rescan your routes using the `php artisan route:scan` command.
  15. @nblackburn nblackburn created this gist Nov 3, 2014.
    9 changes: 9 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # Secure Middleware for Laravel 5

    ## Installation
    - Add `Secure.php` to your `app\Http\Middleware` directory.
    - Add the secure middleware to your route`
    - run `php artisan route:scan`

    ## Notes
    If you are using route annotations, don't forget to rescan your routes using the `php artisan route:scan` command.
    17 changes: 17 additions & 0 deletions Secure.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <?php namespace App\Http\Middleware;

    use Closure;
    use Illuminate\Contracts\Routing\Middleware;

    class Secure implements Middleware {

    public function handle($request, Closure $next)
    {
    if (!$request->secure() && \App::environment() === 'production') {
    return redirect()->secure($request->getRequestUri());
    }

    return $next($request);
    }

    }