Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Latest commit

 

History

History
77 lines (61 loc) · 1.95 KB

File metadata and controls

77 lines (61 loc) · 1.95 KB

论坛

访问地址 https://laravel-workerman.iwnweb.com/

引入 webman/push 适配说明文档

https://github.com/mouyong/laravel-octane-workerman/tree/gatewayworker/webman_plugin_require_example


在 laravel 框架中引入 webman plugin

1. 添加插件安装脚本到项目中

在项目的 composer.json 添加如下内容。可参考 laravel-octane-workermancomposer.json 中,scripts 配置

{
    // ...
    "scripts": {
        "post-package-install": [
            "JieAnthony\\LaravelOctaneWorkerman\\WebmanPlugin::install"
        ],
        "post-package-update": [
            "JieAnthony\\LaravelOctaneWorkerman\\WebmanPlugin::install"
        ],
        "pre-package-uninstall": [
            "JieAnthony\\LaravelOctaneWorkerman\\WebmanPlugin::uninstall"
        ],
        // ...
    }
    // ...
}

2. 引入 webman 插件

composer require webman/push -vvv

3. 适配 laravel 框架

1. 路由适配

  • 修改插件的 route.php 文件
  • Webman\Request 替换为 Illuminate\Http\Request
  • Webman\Route 替换为 Illuminate\Routing\Router
  • 使用 laravel 的路由分组包含路由
  • 替换 Route:: 调用为 $route->

示例:

// use support\Request;
// use Webman\Route;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;

app('router')->middleware(['web'])->group(function (Router $route) {
    /**
     * 推送js客户端文件
     */
    // here before
    // Route::any('plugin/webman/push/push.js', function (Request $request) {
    //    return response()->file(base_path() . '/vendor/webman/push/src/push.js');
    // });

    // here after
    $route->any('plugin/webman/push/push.js', function (Request $request) {
        return response()->file(base_path() . '/vendor/webman/push/src/push.js');
    });
});
  • 手动执行 composer dump-autoload,让项目自动自行 @php artisan package:discover --ansi 命令
composer du # 简写