diff --git a/src/DataTablesServiceProvider.php b/src/DataTablesServiceProvider.php index 546d1cc2..98651d83 100644 --- a/src/DataTablesServiceProvider.php +++ b/src/DataTablesServiceProvider.php @@ -36,6 +36,10 @@ public function boot() */ public function register() { + if ($this->isLumen()) { + require_once 'lumen.php'; + } + $this->app->alias('datatables', DataTables::class); $this->app->singleton('datatables', function () { return new DataTables; @@ -48,6 +52,16 @@ public function register() $this->app->singleton('datatables.config', Config::class); } + /** + * Check if app uses Lumen. + * + * @return bool + */ + protected function isLumen() + { + return str_contains($this->app->version(), 'Lumen'); + } + /** * Get the services provided by the provider. * diff --git a/src/helper.php b/src/helper.php index 4a02ac74..ad22a132 100644 --- a/src/helper.php +++ b/src/helper.php @@ -2,32 +2,6 @@ use Yajra\DataTables\DataTables; -if (!function_exists('config_path')) { - /** - * Get the configuration path. - * - * @param string $path - * @return string - */ - function config_path($path = '') - { - return app()->basePath() . '/config' . ($path ? '/' . $path : $path); - } -} - -if (!function_exists('public_path')) { - /** - * Return the path to public dir - * - * @param null $path - * @return string - */ - function public_path($path = null) - { - return rtrim(app()->basePath('public/' . $path), '/'); - } -} - if (!function_exists('datatables')) { /** * Helper to make a new DataTable instance from source. diff --git a/src/lumen.php b/src/lumen.php new file mode 100644 index 00000000..58b5f58d --- /dev/null +++ b/src/lumen.php @@ -0,0 +1,27 @@ +basePath() . '/config' . ($path ? '/' . $path : $path); + } +} + +if (!function_exists('public_path')) { + /** + * Return the path to public dir + * + * @param null $path + * @return string + */ + function public_path($path = null) + { + return rtrim(app()->basePath('public/' . $path), '/'); + } +}