user roles, bug fixes
This commit is contained in:
17
app/Models/ErpSystemRole.php
Normal file
17
app/Models/ErpSystemRole.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use App\Models\StaffMember;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ErpSystemRole extends Model
|
||||
{
|
||||
protected $guarded = array('id');
|
||||
public $table = "system_roles";
|
||||
|
||||
|
||||
public function staffmembers(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(StaffMember::class, 'user_roles', 'system_role_id', 'staff_member_id');
|
||||
}
|
||||
}
|
||||
@@ -18,4 +18,13 @@ class Mnonote extends Model
|
||||
public function created_by_info(){
|
||||
return $this->hasOne('App\Models\StaffMember', 'id', 'user_id');
|
||||
}
|
||||
public function operator()
|
||||
{
|
||||
return $this->belongsTo(NetworkOperator::class, 'mno_id', 'id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ class NetworkOperator extends Model
|
||||
{
|
||||
return $this->hasMany(NetworkOperatorDocument::class);
|
||||
}
|
||||
public function notes()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Mnonote::class, 'mno_id', 'id')->latest();
|
||||
}
|
||||
/*
|
||||
public function setBuyingRateAttribute($value)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,8 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use App\Traits\LogsActivity;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use App\Models\ErpSystemRole;
|
||||
|
||||
class StaffMember extends Authenticatable
|
||||
{
|
||||
@@ -35,7 +37,22 @@ class StaffMember extends Authenticatable
|
||||
public function department(){
|
||||
return $this->hasOne('App\Models\Department', 'id', 'department_id');
|
||||
}
|
||||
// public function designation(){
|
||||
// return $this->hasOne('App\Models\Department', 'id', 'department_id');
|
||||
// }
|
||||
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
// Parameter order: Related Model, Pivot Table Name, Foreign Key on Pivot, Related Key on Pivot
|
||||
return $this->belongsToMany(ErpSystemRole::class, 'user_roles', 'staff_member_id', 'system_role_id');
|
||||
}
|
||||
|
||||
public function hasRole(string $role): bool
|
||||
{
|
||||
return $this->roles()->where('name', $role)->exists();
|
||||
}
|
||||
|
||||
|
||||
// 4. Cast dates correctly
|
||||
protected $casts = [
|
||||
// 'dob' => 'date',
|
||||
|
||||
Reference in New Issue
Block a user