Code Monkey home page Code Monkey logo

Comments (4)

mtolhuys avatar mtolhuys commented on May 18, 2024 2

Thanks @mtvbrianking!

I think you could do this in a couple of ways:

Only require it in development: composer require mtolhuys/laravel-schematics --dev

You could alternatively provide a Middleware to the route through your config/schematics.php file.

'middleware' => ['dev-env-or-something-similar'],

And then handle the check, block and/or redirect through the middleware.

from laravel-schematics.

mtvbrianking avatar mtvbrianking commented on May 18, 2024 2

The middleware option works just fine. I am leaving the steps here it could help someone else.

Create middleware

<?php

namespace App\Http\Middleware;

use Closure;

class NotInProduction
{
    public function handle($request, Closure $next)
    {
        if (config('app.env') == 'production') {
            abort(403, "Don't run in production.");
        }

        return $next($request);
    }
}

Register middleware: app\Http\Kernel.php

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    // ...

    protected $routeMiddleware = [
        // ...
        
        'dev' => \App\Http\Middleware\NotInProduction::class,
    ];
}

Protect routes; config/schematics

<?php

return [
    // ...
       
    'middleware' => 'dev',
];

You may need to clear the cache for the change to be effected.

php artisan config:clear

from laravel-schematics.

mtvbrianking avatar mtvbrianking commented on May 18, 2024

I had required in --dev but I could still access the routes in production, I am just worried about users stumbling across the database schematics.

Let me write up a middleware to validate and restrict access based on the app environment.

from laravel-schematics.

mtolhuys avatar mtolhuys commented on May 18, 2024

Thanks for sharing @mtvbrianking !

from laravel-schematics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.