Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Remove deprecated Laravel helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidesu committed Sep 6, 2019
1 parent 2a4e2b5 commit f3c438f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/Concerns/HasPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Caffeinated\Shinobi\Concerns;

use Illuminate\Support\Arr;
use Caffeinated\Shinobi\Facades\Shinobi;
use Caffeinated\Shinobi\Contracts\Permission;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
Expand Down Expand Up @@ -68,7 +69,7 @@ public function hasPermissionTo($permission): bool
*/
public function givePermissionTo(...$permissions): self
{
$permissions = array_flatten($permissions);
$permissions = Arr::flatten($permissions);
$permissions = $this->getPermissions($permissions);

if (! $permissions) {
Expand All @@ -88,7 +89,7 @@ public function givePermissionTo(...$permissions): self
*/
public function revokePermissionTo(...$permissions): self
{
$permissions = array_flatten($permissions);
$permissions = Arr::flatten($permissions);
$permissions = $this->getPermissions($permissions);

$this->permissions()->detach($permissions);
Expand All @@ -104,7 +105,7 @@ public function revokePermissionTo(...$permissions): self
*/
public function syncPermissions(...$permissions): self
{
$permissions = array_flatten($permissions);
$permissions = Arr::flatten($permissions);
$permissions = $this->getPermissions($permissions);

$this->permissions()->sync($permissions);
Expand Down
10 changes: 6 additions & 4 deletions src/Concerns/HasRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Caffeinated\Shinobi\Concerns;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Caffeinated\Shinobi\Contracts\Role;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

Expand All @@ -25,7 +27,7 @@ public function roles(): BelongsToMany
*/
public function hasRole($role): bool
{
$slug = str_slug($role);
$slug = Str::slug($role);

return (bool) $this->roles->where('slug', $slug)->count();
}
Expand Down Expand Up @@ -77,7 +79,7 @@ public function hasRoles(): bool
*/
public function assignRoles(...$roles): self
{
$roles = array_flatten($roles);
$roles = Arr::flatten($roles);
$roles = $this->getRoles($roles);

if (! $roles) {
Expand All @@ -97,7 +99,7 @@ public function assignRoles(...$roles): self
*/
public function removeRoles(...$roles): self
{
$roles = array_flatten($roles);
$roles = Arr::flatten($roles);
$roles = $this->getRoles($roles);

$this->roles()->detach($roles);
Expand All @@ -113,7 +115,7 @@ public function removeRoles(...$roles): self
*/
public function syncRoles(...$roles): self
{
$roles = array_flatten($roles);
$roles = Arr::flatten($roles);
$roles = $this->getRoles($roles);

$this->roles()->sync($roles);
Expand Down
4 changes: 3 additions & 1 deletion src/Tactics/AssignRoleTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Caffeinated\Shinobi\Tactics;

use Illuminate\Support\Arr;

class AssignRoleTo
{
/**
Expand All @@ -16,7 +18,7 @@ class AssignRoleTo
*/
public function __construct(...$roles)
{
$this->roles = array_flatten($roles);
$this->roles = Arr::flatten($roles);
}

public function to($user)
Expand Down
3 changes: 2 additions & 1 deletion src/Tactics/GivePermissionTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Caffeinated\Shinobi\Tactics;

use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;
use Caffeinated\Shinobi\Facades\Shinobi;

Expand All @@ -19,7 +20,7 @@ class GivePermissionTo
*/
public function __construct(...$permissions)
{
$this->permissions = array_flatten($permissions);
$this->permissions = Arr::flatten($permissions);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Tactics/RevokePermissionFrom.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Caffeinated\Shinobi\Tactics;

use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;
use Caffeinated\Shinobi\Facades\Shinobi;

Expand All @@ -19,7 +20,7 @@ class RevokePermissionsFrom
*/
public function __construct(...$permissions)
{
$this->permissions = array_flatten($permissions);
$this->permissions = Arr::flatten($permissions);
}

public function to($roleOrUser)
Expand Down
3 changes: 2 additions & 1 deletion tests/factories/PermissionFactory.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Illuminate\Support\Str;
use Caffeinated\Shinobi\Models\Permission;

$factory->define(Permission::class, function(Faker\Generator $faker) {
$name = $faker->unique()->sentence(2);

return [
'name' => $name,
'slug' => str_slug($name, '.'),
'slug' => Str::slug($name, '.'),
'description' => $faker->sentence,
];
});
3 changes: 2 additions & 1 deletion tests/factories/RoleFactory.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Illuminate\Support\Str;
use Caffeinated\Shinobi\Models\Role;

$factory->define(Role::class, function(Faker\Generator $faker) {
$name = $faker->unique()->jobTitle;

return [
'name' => $name,
'slug' => str_slug($name),
'slug' => Str::slug($name),
'description' => $faker->sentence,
'special' => null,
];
Expand Down

0 comments on commit f3c438f

Please sign in to comment.