File, Cache, Storage and friends are Laravel facades. Flarum boots the Illuminate container without registering the facade root, so calling them throws:
RuntimeException: A facade root has not been set.
The fix
Inject the contract instead of reaching for the facade. Flarum's container resolves them normally:
use Illuminate\Contracts\Filesystem\Factory;
public function __construct(protected Factory $filesystem) {}
// then
$disk = $this->filesystem->disk('flarum-assets');
Same pattern for cache (Illuminate\Contracts\Cache\Repository) and the rest. Constructor injection also makes the dependency testable, which the facade never was.
Recommended Comments