1

I'm looking to encapsulate functionality that can be integrated into both a Laravel 5.6 webapp and a PHP-based command-line application. The functionality involves database interactivity.

For the sake of modularity, I decided to implement this functionality as a Composer module. Within the module, a constructor accepts an instance of Illuminate\Database\Capsule\Manager. I believe this to be the appropriate way to use Eloquent outside of Laravel, and thus assumed it would serve as a satisfactory lowest common denominator among Laravel and the CLI-based application. (The module itself works great.)

I am now attempting to wrap this module within a Laravel Service Provider, and am encountering a problem: Laravel seems to mask its underlying Illuminate\Database\Capsule\Manager resource behind a DB "facade", which implements only static methods.

Question: within Laravel, how can I access the underlying Illuminate\Database\Capsule\Manager instance?

I'll note that I've been programming for 15+ years, but am relatively new to Laravel. With that said, if my thinking here is fundamentally contrary to the "Laravel way", please let me know of other architectural options. Thanks.

Chris Allen Lane
  • 6,334
  • 5
  • 25
  • 31
  • were you able to find a answer for this? – Yeak May 09 '18 at 05:30
  • @Yeak, I was not. I've since come to believe that what I wanted to do is simply not possible, and chose to refactor my application accordingly. – Chris Allen Lane May 10 '18 at 15:38
  • I am not sure if this is what you look for but anyway I ended up having a similar situation and I wanted to access the capsule instance when I was creating an application using some of Laravel modules outside Laravel. There is an option to set capsule as `$capsule->setAsGlobal();` which in turn makes capsule instance available globally. So inside controller you may refer to it as `global $capsule`. – ralixyle Aug 04 '18 at 13:19

0 Answers0