[WIP] Setup of skeleton
This commit is contained in:
49
app/Models/Auth/Permission.php
Normal file
49
app/Models/Auth/Permission.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Laratrust\Models\LaratrustPermission;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $display_name
|
||||
* @property string $description
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Role[] $roles
|
||||
*
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Permission whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Permission whereDescription($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Permission whereDisplayName($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Permission whereId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Permission whereName($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Permission whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
|
||||
class Permission extends LaratrustPermission
|
||||
{
|
||||
protected $connection = 'mysql';
|
||||
|
||||
public function application()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Application');
|
||||
}
|
||||
|
||||
public function application_module()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ApplicationModule');
|
||||
}
|
||||
|
||||
public function getDisplayNameAttribute($value)
|
||||
{
|
||||
return __($value);
|
||||
}
|
||||
|
||||
public function getDescriptionAttribute($value)
|
||||
{
|
||||
return __($value);
|
||||
}
|
||||
}
|
||||
30
app/Models/Auth/PermissionRole.php
Normal file
30
app/Models/Auth/PermissionRole.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PermissionRole extends Model
|
||||
{
|
||||
protected $table = 'permission_role';
|
||||
|
||||
public function permission()
|
||||
{
|
||||
return $this->belongsTo('App\Permission');
|
||||
}
|
||||
|
||||
public function role()
|
||||
{
|
||||
return $this->belongsTo('App\Role');
|
||||
}
|
||||
|
||||
public function scopeByPermission($query, $id)
|
||||
{
|
||||
return $query->where('permission_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByRole($query, $id)
|
||||
{
|
||||
return $query->where('role_id', $id);
|
||||
}
|
||||
}
|
||||
45
app/Models/Auth/PermissionUser.php
Normal file
45
app/Models/Auth/PermissionUser.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PermissionUser extends Model
|
||||
{
|
||||
protected $table = 'permission_user';
|
||||
|
||||
public function permission()
|
||||
{
|
||||
return $this->belongsTo('App\Permission');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\User');
|
||||
}
|
||||
|
||||
public function team()
|
||||
{
|
||||
return $this->belongsTo('App\Team');
|
||||
}
|
||||
|
||||
public function scopeByUser($query, $id)
|
||||
{
|
||||
return $query->where('user_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByPermission($query, $id)
|
||||
{
|
||||
return $query->where('permission_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByUserType($query, $name)
|
||||
{
|
||||
return $query->where('user_type', $name);
|
||||
}
|
||||
|
||||
public function scopeByTeam($query, $id)
|
||||
{
|
||||
return $query->where('team_id', $id);
|
||||
}
|
||||
}
|
||||
45
app/Models/Auth/Role.php
Normal file
45
app/Models/Auth/Role.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Laratrust\Models\LaratrustRole;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $display_name
|
||||
* @property string $description
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Permission[] $permissions
|
||||
*
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereDescription($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereDisplayName($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereName($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
|
||||
class Role extends LaratrustRole
|
||||
{
|
||||
protected $connection = 'mysql';
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function getDisplayNameAttribute($value)
|
||||
{
|
||||
return __($value);
|
||||
}
|
||||
|
||||
public function getDescriptionAttribute($value)
|
||||
{
|
||||
return __($value);
|
||||
}
|
||||
|
||||
public function getNbUsers()
|
||||
{
|
||||
return User::whereRoleIs($this->name)->count();
|
||||
}
|
||||
}
|
||||
41
app/Models/Auth/RoleUser.php
Normal file
41
app/Models/Auth/RoleUser.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RoleUser extends Model
|
||||
{
|
||||
protected $table = 'role_user';
|
||||
protected $connection = 'mysql';
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\User');
|
||||
}
|
||||
|
||||
public function team()
|
||||
{
|
||||
return $this->belongsTo('App\Team');
|
||||
}
|
||||
|
||||
public function scopeByUser($query, $id)
|
||||
{
|
||||
return $query->where('user_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByRole($query, $id)
|
||||
{
|
||||
return $query->where('role_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByUserType($query, $name)
|
||||
{
|
||||
return $query->where('user_type', $name);
|
||||
}
|
||||
|
||||
public function scopeByTeam($query, $id)
|
||||
{
|
||||
return $query->where('team_id', $id);
|
||||
}
|
||||
}
|
||||
35
app/Models/Auth/Team.php
Normal file
35
app/Models/Auth/Team.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use Laratrust\Models\LaratrustTeam;
|
||||
|
||||
class Team extends LaratrustTeam
|
||||
{
|
||||
use SoftDeletes;
|
||||
protected $connection = 'mysql';
|
||||
public $timestamps = false;
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->hasMany('App\User');
|
||||
}
|
||||
|
||||
public function society()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Society');
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('active', 1);
|
||||
}
|
||||
|
||||
public function scopeBySociety($query, $id)
|
||||
{
|
||||
return $query->where('society_id', $id);
|
||||
}
|
||||
}
|
||||
31
app/Models/Auth/TeamUser.php
Normal file
31
app/Models/Auth/TeamUser.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TeamUser extends Model
|
||||
{
|
||||
protected $table = 'team_user';
|
||||
protected $connection = 'mysql';
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\User');
|
||||
}
|
||||
|
||||
public function team()
|
||||
{
|
||||
return $this->belongsTo('App\Team');
|
||||
}
|
||||
|
||||
public function scopeByUser($query, $id)
|
||||
{
|
||||
return $query->where('user_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByTeam($query, $id)
|
||||
{
|
||||
return $query->where('team_id', $id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user