public function getNamespace()
{
if (!is_null($this->namespace)) {
return $this->namespace;
}
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) {
foreach ((array) $path as $pathChoice) {
if (realpath(app()->path()) == realpath(base_path() . '/' . $pathChoice)) {
return $this->namespace = $namespace;
}
}
}
throw new RuntimeException('Unable to detect application namespace.');
}