小智 27
Claudio的诊断是正确的,在第3版中添加了名称空间Pusher; 但更改Laravel文件不是推荐的解决方案.
更好的方法是在中创建别名config/app.php.在"别名"键下,将其添加到"第三方别名"部分中的数组中:
'Pusher' => Pusher\Pusher::class,
Run Code Online (Sandbox Code Playgroud)
(OP 在问题中发布了以下答案。根本问题是Pusher-php-server的版本 3引入了命名空间,因此现在需要use Pusher\Pusher。)
创建这个命令:
namespace App\Console\Commands;
use Illuminate\Support\Facades\File;
use Illuminate\Console\Command;
class FixPusher extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fix:pusher';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fix Pusher namespace issue';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$broadcastManagerPath = base_path('vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php');
$pusherBroadcasterPath = base_path('vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php');
$contents = str_replace('use Pusher;', 'use Pusher\Pusher;', File::get($broadcastManagerPath));
File::put($broadcastManagerPath, $contents);
$contents = str_replace('use Pusher;', 'use Pusher\Pusher;', File::get($pusherBroadcasterPath));
File::put($pusherBroadcasterPath, $contents);
}
}
Run Code Online (Sandbox Code Playgroud)
然后添加"php artisan fix:pusher"到composer.json文件中:
"post-update-cmd": [
"php artisan fix:pusher",
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8702 次 |
| 最近记录: |