I am trying to this data through this code
Auth::user()->personnel->currentAssignment->role->is_allowed
but I am getther null value because the suppose role value return assignment, instead of role data.
This is working fine Auth::user()->personnel->currentAssignment
so far, but once I join the role
, Im getting PersonnelAssignment
data instead of RoleCatelog
which causes to null
value
please Im new to Laravel. I need your help.
As you can see it return this data:
"current_assignment": {
"id": "778",
"personnel_id": "100751",
"area_id": 154,
"role_id": 17,
"dept_id": 154,
"start_date": "2017-11-08",
"end_date": null,
"is_temporary": null,
"is_deleted": null,
"modify_id": "Sample Name",
"modify_dt": null,
"create_id": "Administrator",
"create_dt": null,
"transfer_id": null,
"transfer_dt": null,
"role": {
"id": "101",
"personnel_id": null,
"area_id": 154,
"role_id": 17,
"dept_id": 154,
"start_date": "2007-05-04",
"end_date": null,
"is_temporary": null,
"is_deleted": null,
"modify_id": "Sample Name II",
"modify_dt": null,
"create_id": "Sample Name II",
"create_dt": null,
"transfer_id": null,
"transfer_dt": null
}
}
This for assignment model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;
class PersonnelAssignment extends Model
{
protected $table = 'smed_personnel_assignment';
protected $primaryKey = 'id';
protected $keyType = 'string';
public $incrementing = false;
public $timestamps = false;
protected $fillable = [
'id',
'personnel_id',
'area_id',
'role_id',
'dept_id',
'start_date',
'end_date',
'modify_id',
'modify_dt',
'create_id',
'create_dt',
];
public function role(){
return $this->belongsTo(RoleCatalog::class, 'role_id');
}
}
And this is for role model...
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RoleCatalog extends Model
{
protected $table = 'smed_personnel_assignment';
protected $primaryKey = 'role_id';
public $incrementing = false;
public $timestamps = false;
protected $fillable = [
'role_id',
'role_name',
'role_desc',
'role_area',
'is_allowed',
'is_deleted',
'modify_id',
'modify_dt',
'create_id',
'create_dt',
];
}
..