Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Laravel 7 #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -45,6 +45,6 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"orchestra/testbench": "^4.0"
"orchestra/testbench": "^5.0|^6.0"
}
}
33 changes: 0 additions & 33 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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'))
));
}
}
7 changes: 4 additions & 3 deletions src/Otter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/OtterApplicationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
});
}

Expand Down