I've another relation that attach to role but when I tried to call it in controller with with/load/relations model it doesn't work. I can't call any relationship in role model except permissions.
class Role extends \Spatie\Permission\Models\Role
{
public static $rules = [
'name'=>'required'
];
//protected $relations = ['satkers'];
//protected $with = ['satkers'];
//RELATIONS
public function satkers(){
return $this->belongsTo(MasterSatker::class, 'master_pelaksana_satker_id', 'id')->withDefault(['name'=>'']);
}
}
How call it in controller?
I've tried show it like this $role->load('satkers')
and $role->satkers
, it doesn't work. I got an error Call to undefined relationship [satkers] on model [Spatie\Permission\Models\Role]
and null. I tried dd the $role, here is it what i got
Spatie\Permission\Models\Role {#1587 ▼
#guarded: array:1 [▶]
#connection: "mysql"
#table: "roles"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:6 [▶]
#original: array:6 [▶]
#changes: []
#casts: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▼ //it just show permissions
"permissions" => Illuminate\Database\Eloquent\Collection {#1975 ▶}
]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
-permissionClass: null
}