按照官方的文檔安裝 psr/container ^v1 和 jenssegers/blade ~1.4.0后再安裝illuminate/database,始終不成功,報(bào)錯(cuò):
composer require -W illuminate/database illuminate/pagination illuminate/events
Using version ^9.12 for illuminate/database
Using version ^9.12 for illuminate/pagination
Using version ^9.12 for illuminate/events
./composer.json has been updated
Running composer update illuminate/database illuminate/pagination illuminate/events --with-all-dependencies
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
You can also try re-running composer require with an explicit version constraint, e.g. "composer require illuminate/database:*" to figure out if any version is installable, or "composer require illuminate/database:^2.1" if you know which you need.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
系統(tǒng):windows 11
PHP: 8.1.2
Composer: 2.3.5
composer.json如下
"require": {
"php": ">=7.2",
"workerman/webman-framework": "^1.3.13",
"monolog/monolog": "^3.0.0",
"psr/container": "v1",
"jenssegers/blade": "^1.4"
},
"suggest": {
"ext-event": "For better performance. "
},
"autoload": {
"psr-4": {
"": "./",
"App\\": "./app"
},
"files": [
"./support/helpers.php"
]
},
"scripts": {
"post-package-install": [
"support\\Plugin::install"
],
"post-package-update": [
"support\\Plugin::install"
],
"pre-package-uninstall": [
"support\\Plugin::uninstall"
]
}
貌似是跟psr/container ^v1 jenssegers/blade ~1.4.0 沖突?。。?!
各種版本間沖突太折磨人了。。
腫么辦?????
下面的兩個(gè)擴(kuò)展版本。
"illuminate/redis": "^9.4",
"illuminate/database": "^9.4",
我安裝的是這個(gè)版本。
php8.0.8 版。
composer info 如下:
illuminate/collections v9.11.0 The Illuminate Collections package.
illuminate/conditionable v9.11.0 The Illuminate Conditionable package.
illuminate/container v9.11.0 The Illuminate Container package.
illuminate/contracts v9.11.0 The Illuminate Contracts package.
illuminate/database v9.11.0 The Illuminate Database package.
illuminate/macroable v9.11.0 The Illuminate Macroable package.
illuminate/redis v9.11.0 The Illuminate Redis package.
illuminate/support v9.11.0 The Illuminate Support package.
如果安裝了psr/container ^v1 和 jenssegers/blade ~1.4.0, illuminate/redis也同樣安裝不了
強(qiáng)烈建議放棄擁抱jenssegers/blade吧,它已經(jīng)不更新了
我的終極解決方案:
用 standalone-blade(https://github.com/ryangjchandler/standalone-blade )取代了jenssegers/blade。供大家參考~
use Illuminate\Config\Repository;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Contracts\Container\Container as ContainerContract;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Facade;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\ViewServiceProvider;
/**
* @mixin \Illuminate\Contracts\View\Factory
* @mixin \Illuminate\View\Compilers\BladeCompiler
*/
class Blade
{
protected Factory $factory;
protected BladeCompiler $compiler;
final public function __construct(
protected string|array $viewPaths,
protected string $cachePath,
protected ?ContainerContract $container = null
) {
$this->viewPaths = Arr::wrap($viewPaths);
$this->init();
}
protected function init()
{
$this->container ??= new Container;
$this->container->singleton('files', fn () => new Filesystem);
$this->container->singleton('events', fn () => new Dispatcher);
$this->container->singleton('config', fn () => new Repository([
'view.paths' => $this->viewPaths,
'view.compiled' => $this->cachePath,
]));
(new ViewServiceProvider($this->container))->register();
$this->factory = $this->container->get('view');
$this->compiler = $this->container->get('blade.compiler');
}
public function __call(string $name, array $arguments)
{
if (method_exists($this->compiler, $name)) {
return $this->compiler->{$name}(...$arguments);
}
return $this->factory->{$name}(...$arguments);
}
public static function new(string $viewPath, string $cachePath, ?ContainerContract $container = null)
{
return new static($viewPath, $cachePath, $container);
}
public function render(string $viewPath, array $arguments = []): string
{
return $this->make($viewPath, $arguments);
}
}