diff --git a/composer.json b/composer.json index cf90741..3a4ca58 100755 --- a/composer.json +++ b/composer.json @@ -14,9 +14,9 @@ } ], "require": { - "php": ">=7.2", - "illuminate/console": "^6.0", - "illuminate/routing": "^6.0" + "php": "^7.2.5|^8.0", + "illuminate/console": "^7.0|^8.0", + "illuminate/routing": "^7.0|^8.0" }, "autoload": { "psr-4": { @@ -45,6 +45,6 @@ "minimum-stability": "dev", "prefer-stable": true, "require-dev": { - "orchestra/testbench": "^4.0" + "orchestra/testbench": "^5.0|^6.0" } } diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 32db54a..12675e4 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -4,12 +4,9 @@ use Illuminate\Support\Str; use Illuminate\Console\Command; -use Illuminate\Console\DetectsApplicationNamespace; class InstallCommand extends Command { - use DetectsApplicationNamespace; - /** * The name and signature of the console command. * @@ -40,36 +37,6 @@ public function handle() $this->comment('Publishing Otter Configuration...'); $this->callSilent('vendor:publish', ['--tag' => 'otter-config']); - $this->registerOtterServiceProvider(); - $this->info('Otter scaffolding installed successfully.'); } - - /** - * Register the Otter service provider in the application configuration file. - * - * @return void - */ - protected function registerOtterServiceProvider() - { - $namespace = Str::replaceLast('\\', '', $this->getAppNamespace()); - - $appConfig = file_get_contents(config_path('app.php')); - - if (Str::contains($appConfig, $namespace.'\\Providers\\OtterServiceProvider::class')) { - return; - } - - file_put_contents(config_path('app.php'), str_replace( - "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL, - "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL." {$namespace}\Providers\OtterServiceProvider::class,".PHP_EOL, - $appConfig - )); - - file_put_contents(app_path('Providers/OtterServiceProvider.php'), str_replace( - "namespace App\Providers;", - "namespace {$namespace}\Providers;", - file_get_contents(app_path('Providers/OtterServiceProvider.php')) - )); - } } diff --git a/src/Otter.php b/src/Otter.php index 036ce10..d345c02 100755 --- a/src/Otter.php +++ b/src/Otter.php @@ -3,6 +3,7 @@ namespace Poowf\Otter; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Gate; use Illuminate\Support\Str; use Illuminate\Support\Facades\File; use Poowf\Otter\Http\Resources\OtterResource; @@ -45,12 +46,12 @@ class Otter */ public static function check($request) { - return (static::$authUsing ?: function () { - return app()->environment('local'); - })($request); + return app()->environment('local') + ?: Gate::check('viewOtter', [$request->user()]); } /** + * * Set the callback that should be used to authenticate Otter users. * * @param \Closure $callback diff --git a/src/OtterApplicationServiceProvider.php b/src/OtterApplicationServiceProvider.php index 89ff0da..a2c0fa9 100644 --- a/src/OtterApplicationServiceProvider.php +++ b/src/OtterApplicationServiceProvider.php @@ -27,8 +27,8 @@ protected function authorization() $this->gate(); Otter::auth(function ($request) { - return app()->environment('local') || - Gate::check('viewOtter', [$request->user()]); + return app()->environment('local') + ?: Gate::check('viewOtter', [$request->user()]); }); }