Question: How can I inject a disk in my code (constructors or controller methods)?
Related to: https://laravel.com/docs/5.4/filesystem#obtaining-disk-instances
What I want is to do something like
function __construct(Disk $disk)
{
}
instead of this
function __construct(Disk $disk)
{
$disk = Storage::disk('files');
}
later edit 1:
Using all the time $disk = Storage::disk('files');
in my service classes or controllers looks to me a litle bit "hardcoded". I might have differente service classes like, SendImageOnEmail
, OptimizeImage
and the disk instance its an infrastructure dependency. To me it seems that is should be injected trough constructor.