Skip to content

Commit

Permalink
Updating the Auth Models
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Sep 24, 2016
1 parent c6081b4 commit a4bd787
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 16 deletions.
18 changes: 16 additions & 2 deletions src/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Permission extends BasePermissionModel
*/
public function getHashedIdAttribute()
{
return hasher()->encode($this->id);
return self::hasher()->encode($this->id);
}

/* ------------------------------------------------------------------------------------------------
Expand All @@ -39,7 +39,7 @@ public function getHashedIdAttribute()
*/
public static function firstHashedOrFail($hashedId)
{
$id = head(hasher()->decode($hashedId));
$id = self::hasher()->decode($hashedId);

return self::where('id', $id)->firstOrFail();
}
Expand Down Expand Up @@ -67,4 +67,18 @@ public function hasGroup()
{
return $this->group_id !== 0;
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Get the hasher.
*
* @return \Arcanedev\Hasher\Contracts\HashManager
*/
protected static function hasher()
{
return hasher();
}
}
18 changes: 16 additions & 2 deletions src/Models/PermissionsGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PermissionsGroup extends BasePermissionsGroupModel
*/
public function getHashedIdAttribute()
{
return hasher()->encode($this->id);
return self::hasher()->encode($this->id);
}

/* ------------------------------------------------------------------------------------------------
Expand All @@ -41,8 +41,22 @@ public function getHashedIdAttribute()
*/
public static function firstHashedOrFail($hashedId)
{
$id = head(hasher()->decode($hashedId));
$id = self::hasher()->decode($hashedId);

return self::where('id', $id)->firstOrFail();
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Get the hasher.
*
* @return \Arcanedev\Hasher\Contracts\HashManager
*/
protected static function hasher()
{
return hasher();
}
}
27 changes: 21 additions & 6 deletions src/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
* @package Arcanesoft\Auth\Models
* @author ARCANEDEV <[email protected]>
*
* @method static \Illuminate\Database\Eloquent\Builder admins()
* @method static \Illuminate\Database\Eloquent\Builder members()
* @method static \Illuminate\Database\Eloquent\Builder admin()
* @method static \Illuminate\Database\Eloquent\Builder moderator()
* @method static \Illuminate\Database\Eloquent\Builder member()
*/
class Role extends BaseRoleModel
{
Expand All @@ -33,7 +34,7 @@ class Role extends BaseRoleModel
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeAdmins(Builder $query)
public function scopeAdmin(Builder $query)
{
return $query->where('slug', Role::ADMINISTRATOR);
}
Expand All @@ -57,7 +58,7 @@ public function scopeModerator(Builder $query)
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeMembers(Builder $query)
public function scopeMember(Builder $query)
{
return $query->where('slug', Role::MEMBER);
}
Expand All @@ -73,7 +74,7 @@ public function scopeMembers(Builder $query)
*/
public function getHashedIdAttribute()
{
return hasher()->encode($this->id);
return self::hasher()->encode($this->id);
}

/* ------------------------------------------------------------------------------------------------
Expand All @@ -91,7 +92,7 @@ public function getHashedIdAttribute()
*/
public static function firstHashedOrFail($hashedId)
{
$id = head(hasher()->decode($hashedId));
$id = self::hasher()->decode($hashedId);

return self::where('id', $id)->firstOrFail();
}
Expand All @@ -105,4 +106,18 @@ public function makeSlugName($value)
{
return $this->slugify($value);
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Get the hasher.
*
* @return \Arcanedev\Hasher\Contracts\HashManager
*/
protected static function hasher()
{
return hasher();
}
}
24 changes: 18 additions & 6 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class User extends BaseUserModel
*/
public function getHashedIdAttribute()
{
return hasher()->encode($this->id);
return self::hasher()->encode($this->id);
}

/**
Expand All @@ -33,7 +33,7 @@ public function getHashedIdAttribute()
*/
public function getFullNameAttribute()
{
$fullName = trim($this->first_name . ' ' . $this->last_name);
$fullName = trim("{$this->first_name} {$this->last_name}");

return empty($fullName) ? $this->username : $fullName;
}
Expand Down Expand Up @@ -77,11 +77,9 @@ public function getSinceDateAttribute()
*/
public static function firstHashedOrFail($hashedId)
{
$id = head(hasher()->decode($hashedId));
$id = self::hasher()->decode($hashedId);

return self::withTrashed()
->where('id', $id)
->firstOrFail();
return self::withTrashed()->where('id', $id)->firstOrFail();
}

/* ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -117,4 +115,18 @@ public function isMember()
{
return $this->hasRoleSlug(Role::MEMBER);
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Get the hasher.
*
* @return \Arcanedev\Hasher\Contracts\HashManager
*/
protected static function hasher()
{
return hasher();
}
}

0 comments on commit a4bd787

Please sign in to comment.