php - Laravel 5.6 在没有命令的情况下启动站点

标签 php laravel laravel-5.6 laravel-artisan

我有一个 Laravel 5.6 网站,我希望为非技术管理员启用此功能,以便他可以随时关闭或打开网站。

我已经通过使用成功关闭了网站

    Route::get('shut/down', function() {
        `Artisan::call('down');`
    });

但是当我希望我的应用程序使用它进行备份时

Route::get('bring/the/application/back/up', function() 
{
    Artisan::call('up');
});

但这行不通,因为我的网站已经关闭,所以这行不通。 但是在命令行中,我们有一些命令可以通过这些命令排除维护模式的 IP 地址。


例子: php artisan down --allow=127.0.0.1 --allow=192.168.0.0/16

我们是否有任何解决方法可以在不使用命令行方法的情况下排除某些选定的 IP 地址,或者在不使用命令的情况下恢复站点?

最佳答案

你必须仔细看看 Official documentation它解释了如何以编程方式调用命令:

Sometimes you may wish to execute an Artisan command outside of the CLI. For example, you may wish to fire an Artisan command from a route or controller. You may use the call method on the Artisan facade to accomplish this. The call method accepts either the command's name or class as the first argument, and an array of command parameters as the second argument. The exit code will be returned:

Route::get('/foo', function () {
    $exitCode = Artisan::call('email:send', [
        'user' => 1, '--queue' => 'default'
    ]);

    //
});

因此,在您的情况下,您必须更新路由回调:

Route::get('shut/down', function() {
    Artisan::call('email:send', [
        '--allow' => 'xxxx.xxxx.xxxx.xxxx' // Your ip address
    ]);
});

这样,你的ip地址就可以访问bring/the/application/back/up地址了。无论如何,如果你只是想简单地“隐藏”前端,我会寻找一个不同的解决方案,方法是创建一个“隐藏”网站但保持管理面板以激活/停用的特定变量(配置、数据库等)以更简单的方式。

关于php - Laravel 5.6 在没有命令的情况下启动站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54073266/

相关文章:

php - 带有 PHP 的远程 MySQL 服务器连接

php - 从选择增量mysql更新

mysql - Laravel Eloquent 地查询聚合值的 groupBy

laravel - 如何使用第二个表 Laravel 的 where ?

php - 在 laravel 查询生成器中使用数字,其中语句返回正确的响应,但在使用包含数字的变量时返回错误的响应

php - Laravel 5.6 中的 PATCH 请求

php - ssh 连接在 php 中不起作用

php - 如何转换为在 View 中使用 Yii CDataProvider?

laravel - 在 Laravel 包中的路由上使用显式或隐式模型绑定(bind)

laravel - 按子查询对主查询排序