mardi 21 juin 2016

Lumen Cache\Store is not instantiable

I'm quite new to Laravel and Lumen, so my question may be a little simple, but I couldn't find any useful answer yet.

Lumen version is 5.1.

So I tried to create a data repository supported by a cache. Firstly I want to use FileStore, then I want to move to some more appropriate.

I tried to inject Cache repository like this:

<?php

    namespace App\Repositories;

    use Illuminate\Cache\Repository;

    class DataRepository
    {
        private $cache;

        public function __construct(Repository $cache)
        {
            $this->cache = $cache;
        }
    }

It seemed pretty simple to me. But when I try to use this repo in my controller, and tried to inject this repo into it, during instantiation I get the following error:

BindingResolutionException in Container.php line 749:
Target [Illuminate\Contracts\Cache\Store] is not instantiable.

I guessed the repository cannot find the matching and useable store implementation. When I tried to bind the Store to \Illumante\Cache\FileStore like this:

$this->app->bind(\Illuminate\Contracts\Cache\Store::class, \Illuminate\Cache\FileStore::class);

I got a new kind of error:

Unresolvable dependency resolving [Parameter #1 [ <required> $directory ]] in class Illuminate\Cache\FileStore

I guess I have a more complicated config issue, so I didn't want to walk through the dependency tree.

In my .env I have these:

CACHE_DRIVER=file and SESSION_DRIVER=file

In Lumen I explicitly enabled the facades, the DotEnv (and the eloquent also for my data repositories).

Dotenv::load(__DIR__.'/../');

$app = new Laravel\Lumen\Application(
    realpath(__DIR__.'/../')
);

$app->withFacades();
$app->withEloquent();

I tried to add a cache.php configuration. In the bootstrap/app.php I added $app->configure('cache'); to use it with the following configs:

<?php

return [
    'default' => env('CACHE_DRIVER', 'file'),

    'stores' => [
        'file' => [
            'driver' => 'file',
            'path' => storage_path('framework/cache'),
        ],
    ],
];

Could you help me, how can I bootstrap the Cache properly?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire