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

Fix getByRoles And getActivesByUser #166

Open
wants to merge 3 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "artesaos/defender",
"name": "mstfkhazaal/defender",
"description": "Roles & Permissions for Laravel",
"license": "MIT",
"authors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Artesaos\Defender\Exceptions\PermissionExistsException;
use Carbon\Carbon;
use Illuminate\Contracts\Foundation\Application;

use Illuminate\Support\Facades\DB;
/**
* Class EloquentPermissionRepository.
*/
Expand Down Expand Up @@ -56,6 +56,11 @@ public function getByRoles(array $rolesIds)
{
return $this->model->whereHas('roles', function ($query) use ($rolesIds) {
$query->whereIn('id', $rolesIds);
$query->where('value', true);
$query->where(function ($q) {
$q->where('expires', '>=', Carbon::now());
$q->orWhereNull('expires');
});
})->get();
}

Expand All @@ -67,7 +72,9 @@ public function getByRoles(array $rolesIds)
public function getActivesByUser($user)
{
$table = $user->permissions()->getTable();

if ($user->isSuperUser()) {
return DB::table(config('defender.permission_table', 'permissions'))->get();
}
return $user->permissions()
->where($table.'.value', true)
->where(function ($q) use ($table) {
Expand Down