I want to pass $this
from my Controller to my Service Provider so I can use it with my custom class. That way, I can reference back to my controller and output the success.
Controller
function Foo(){
//$this is defined
MyFacade::Bar($input);
}
function success(){
return var_dump('Succes!');
}
Service Provider
<?php namespace App\Libraries\Extensions\Filesystem;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
use App\Libraries\Extensions\Filesystem\Filesystem;
class FilesystemServiceProvider extends IlluminateServiceProvider {
public function register()
{
$this->app->bind('files', function(){
return new Filesystem($this);
});
}
}
Custom Class
<?php namespace App\Libraries\Extensions\Filesystem;
use \Illuminate\Filesystem\Filesystem as IlluminateFilesystem;
class Filesystem extends IlluminateFilesystem {
protected $listener;
public function __construct($listener)
{
$this->listener = $listener;
}
function Bar($input){
//Some code
return $this->listener->Success();
}
With this code I'm getting Call to undefined method App\Libraries\Extensions\Filesystem\FilesystemServiceProvider::Success()
.
I believe that my Service Provider $this
is passed instead of my Controller $this
.
How can I pass my Controller $this
to my Service Provider so I can just call MyFacade::Bar($input)
?