使用laravel-admin接入laravel-s(swoole)需要兼容修改的地方,持续更新

96
never615
0.1 2019.06.14 19:33* 字数 181

laravel-admin版本: 1.7.1
swoole版本: Version => 4.4.0-alpha
php版本: PHP 7.2.14

中间件中重置对象

    //建一个middleware,请求进来的时候删掉之前缓存的controller对象
    public function handle($request, Closure $next)
    {
        if (PHP_SAPI === 'cli') {
            unset(Route::current()->controller);

            //专门针对laravel-admin的处理
            app()->forgetInstance(Admin::class);
            Facade::clearResolvedInstance(Admin::class);
            
            //最好是源码修改不用静态变量了,但是不知道作者有没有意向接收修改
            Admin::$script=[];
            Admin::$style=[];
            Admin::$css=[];
            Admin::$js=[];
            Admin::$html=[];
            Admin::$headerJs=[];
            Admin::$manifestData=[];
            Admin::$min=[
                'js'  => 'vendor/laravel-admin/laravel-admin.min.js',
                'css' => 'vendor/laravel-admin/laravel-admin.min.css',
            ];
            Admin::$baseCss=[
                'vendor/laravel-admin/AdminLTE/bootstrap/css/bootstrap.min.css',
                'vendor/laravel-admin/font-awesome/css/font-awesome.min.css',
                'vendor/laravel-admin/laravel-admin/laravel-admin.css',
                'vendor/laravel-admin/nprogress/nprogress.css',
                'vendor/laravel-admin/sweetalert2/dist/sweetalert2.css',
                'vendor/laravel-admin/nestable/nestable.css',
                'vendor/laravel-admin/toastr/build/toastr.min.css',
                'vendor/laravel-admin/bootstrap3-editable/css/bootstrap-editable.css',
                'vendor/laravel-admin/google-fonts/fonts.css',
                'vendor/laravel-admin/AdminLTE/dist/css/AdminLTE.min.css',
            ];
            Admin::$baseJs=[
                'vendor/laravel-admin/AdminLTE/bootstrap/js/bootstrap.min.js',
                'vendor/laravel-admin/AdminLTE/plugins/slimScroll/jquery.slimscroll.min.js',
                'vendor/laravel-admin/AdminLTE/dist/js/app.min.js',
                'vendor/laravel-admin/jquery-pjax/jquery.pjax.js',
                'vendor/laravel-admin/nprogress/nprogress.js',
                'vendor/laravel-admin/nestable/jquery.nestable.js',
                'vendor/laravel-admin/toastr/build/toastr.min.js',
                'vendor/laravel-admin/bootstrap3-editable/js/bootstrap-editable.min.js',
                'vendor/laravel-admin/sweetalert2/dist/sweetalert2.min.js',
                'vendor/laravel-admin/laravel-admin/laravel-admin.js',
            ];
        }

        return $next($request);
    }

兼容导出

需要修改laravel-admin的源码,见: https://github.com/never615/laravel-admin/commit/c3de6466ef1e432f62ac7fd848f85b6c42465f7d

controller中需要手动调用一下导出方法:

    public function index()
    {
        $grid = $this->grid();
        if (request(Exporter::$queryName)) {
            return $grid->handleExportRequest();
        }

        return Admin::content(function (Content $content) use ($grid) {
            $content->header($this->getHeaderTitle());
            $content->description($this->getIndexDesc());
            $content->body($grid->render());
        });
    }

可以进一步封装然后就不必手动调用$grid->handleExportRequest()方法,
但是这样要多改几处代码,同时也会执行不必要的 $content->body()等方法,就没封装进去.

还要自定义导出类,可以参考我写的(主要是改用response()->streamDownload):
https://github.com/never615/laravel-admin-enhance/blob/master/src/Grid/Exporters/CsvExporter.php
然后修改config中admin.exporter为你新写的导出类

web