Laravel/Lumen 安装出现 InvalidArgumentException

解决 Laravel/Lumen 出现 "Please provide a valid cache path" 问题。

composer install出现如下错误提示:

...
> @php artisan package:discover --ansi

   InvalidArgumentException

  Please provide a valid cache path.

  at vendor/laravel/framework/src/Illuminate/View/Compilers/Compiler.php:36
     32▕      */
     33▕     public function __construct(Filesystem $files, $cachePath)
     34▕     {
     35▕         if (! $cachePath) {
  ➜  36▕             throw new InvalidArgumentException('Please provide a valid cache path.');
     37▕         }
     38▕
     39▕         $this->files = $files;
     40▕         $this->cachePath = $cachePath;

      +19 vendor frames
  20  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Encore\Admin\AdminServiceProvider))

      +5 vendor frames
  26  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
changedeMacBook-Pro:laravel6Admin changeluo$ php artisan package:discover --ansi

   InvalidArgumentException

  Please provide a valid cache path.

  at vendor/laravel/framework/src/Illuminate/View/Compilers/Compiler.php:36
     32▕      */
     33▕     public function __construct(Filesystem $files, $cachePath)
     34▕     {
     35▕         if (! $cachePath) {
  ➜  36▕             throw new InvalidArgumentException('Please provide a valid cache path.');
     37▕         }
     38▕
     39▕         $this->files = $files;
     40▕         $this->cachePath = $cachePath;

      +19 vendor frames
  20  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Encore\Admin\AdminServiceProvider))
...

这个路径是在 config/cache.php 中指定的,可以自行修改成其他地址:

// cache 配置文件示例  
return [
    // ...
    'stores' => [
        // ...
        'file' => [
            'driver' => 'file',
            'path'   => storage_path('framework/cache'), //缓存地址
        ],
    ],
    // ...  
]

创建目录:

mkdir -p storage/framework/views
mkdir -p storage/framework/cache
mkdir -p storage/framework/sessions

确保 storage 目录结构如下:

./storage
├── app
├── framework
│   ├── cache
│   ├── sessions
│   └── views
└── logs
    └── lumen.log

注意这些目录要有读写权限。