I have to write Custom Service provider in Laravel 5 and I am getting this error:
[Symfony\Component\Debug\Exception\FatalErrorException] Call to undefined method Illuminate\Support\Facades\Cache::forever()
Here is my code:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use TADPHP\TADFactory;
use Cache;
class TADServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$options = [
'ip' => '192.168.0.201',
'internal_id' => 1,
'com_key' => 0,
'soap_port' => 80,
'udp_port' => 4370,
'encoding' => 'utf-8', // iso8859-1 by default.
'connection_timeout' => 2
];
Cache::forever('options', $options);
// $this->app->instance('TADF',$this->app->make('TADPHP\TADFactory', [$options])->get_instance());
$this->app->bind('TADF', 'TADPHP\TADFactory', function($app)
{
return new TADPHP\TADFactory(Cache::get('options'));
});
}
}
Basically I am trying to store the options array in cache and later in my app when I call app()->make('TADF')
to get an instance of this class using the options stored in cache. I am new to Laravel, so there is a better way to do this. Thanks.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire