Answer the question
In order to leave comments, you need to log in
How to hang interfaces on Laravel disks through ioc?
Hey!
Laravel has disks. It's cool and convenient. But calling configs in code is not convenient and not beautiful.
There is an idea to make ioc work according to this principle: I throw in the constructor, for example, TemporaryDisk (interface or class, it doesn’t matter) and I will receive the desired, configured disk.
But when throwing, the designer swears that the adapter has arrived.
Service::__construct() must implement interface App\Disks\TemporaryDisk, instance of Illuminate\Filesystem\FilesystemAdapter given
$this->app->bind(TemporaryDisk::class, static fn() => Storage::disk(
(string) config('disks.tmp')
));
Answer the question
In order to leave comments, you need to log in
Crap idea. You resolve TemporaryDisk (your interface) and get Filesystem as a result? This is nonsense. Here's an exception for you, it's absolutely logical that he flew in.
A more adequate solution is to create a factory and resolve the disks there, inject the factory accordingly.
If you really want to use this crutch - extend TemporaryDisk from FilesystemAdapter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question