Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: amiryousefi/laravel-permission
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.3
Choose a base ref
...
head repository: amiryousefi/laravel-permission
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 10 commits
  • 4 files changed
  • 3 contributors

Commits on Mar 26, 2022

  1. Copy the full SHA
    b61f36c View commit details
  2. Merge pull request #17 from aahelali/Enhance-has-role-trait

    Fix duplicate get user role on HasRole trait
    amiryousefi authored Mar 26, 2022
    Copy the full SHA
    4469dfe View commit details

Commits on Nov 11, 2024

  1. Copy the full SHA
    93bd088 View commit details
  2. Merge pull request #19 from amiryousefi/amiryousefi-patch-1

    Update 2020_04_17_155932_add_role_id_to_users.php
    amiryousefi authored Nov 11, 2024
    Copy the full SHA
    1d21436 View commit details
  3. Copy the full SHA
    24b3f20 View commit details
  4. Copy the full SHA
    2cc2530 View commit details
  5. Merge pull request #20 from amiryousefi/update-migration-files

    Update 2020_04_17_160240_create_permission_table.php
    amiryousefi authored Nov 11, 2024
    Copy the full SHA
    f1301dd View commit details

Commits on Dec 6, 2024

  1. Add 2 scope to Role model

    aahelali committed Dec 6, 2024
    Copy the full SHA
    e3e84d0 View commit details
  2. Merge pull request #21 from amiryousefi/enhance-role-model

    Add 2 scope to Role model
    aahelali authored Dec 6, 2024
    Copy the full SHA
    66b491c View commit details
  3. Hotfix scopeNames

    aahelali committed Dec 6, 2024
    Copy the full SHA
    521831f View commit details
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ public function up()
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['role_id']);
$table->dropColumn('role_id');
});
}
Original file line number Diff line number Diff line change
@@ -27,6 +27,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('permission');
Schema::dropIfExists('permissions');
}
}
11 changes: 11 additions & 0 deletions src/Models/Role.php
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

namespace Amir\Permission\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class Role extends Model
@@ -10,6 +11,16 @@ class Role extends Model

protected $fillable = ['name'];

public function scopeName(Builder $query, string $name)
{
$query->where('name', $name);
}

public function scopeNames(Builder $query, array $names)
{
$query->whereIn('name', $names);
}

public function permissions()
{
return $this->belongsToMany(Permission::class);
2 changes: 1 addition & 1 deletion src/Traits/HasRoles.php
Original file line number Diff line number Diff line change
@@ -12,6 +12,6 @@ public function role()
}

public function getRoleNameAttribute(){
return $this->role()->first() ? $this->role()->first()->name : null ;
return $this->role()->first()->name ?? null ;
}
}