mercredi 13 juillet 2016

Multiple with in Laravel Query: Laravel 5.2.37

Model 1

class RoleModel extends Model {

    public $table = 'tblrole';
    public $primaryKey = 'RoleID';
    public $timestamps = true;

    public function RoleBasedPermissions() {
        return $this->hasMany('App\Models\Role\RolePermissionModel', 'RoleID', 'RoleID');
    }
}

Model 2

class RolePermissionModel extends Model
{
    public $table = 'tblrolepermission';
    public $primaryKey = 'RolePermissionID';
    public $timestamps = false;

    public function Permission() {
        return $this->hasOne('App\Models\Role\RolePermissionModel', 
            'PermissionID', 'PermissionID');
    }

    public function Role() {
        return $this->hasOne('App\Models\Role\RoleModel', 
            'RoleID', 'RoleID');
    }
}

Model 3

class PermissionModel extends Model
{
    public $table = 'tblpermission';
    public $primaryKey = 'PermissionID';
    public $timestamps = false;

    public function Module() {
        return $this->hasOne('App\Models\Role\ModuleModel', 
            'ModuleID', 'ModuleID');
    }

    public function Action() {
        return $this->hasOne('App\Models\Role\ActionModel', 
            'ActionID', 'ActionID');
    }
}

My Query is below

$data = RoleModel
    ::where('RoleID', $RoleID)
    ->with('RoleBasedPermissions')
    ->with('RoleBasedPermissions.Permission')
    ->with('RoleBasedPermissions.Permission.Module')
    ->get();  

Error

Call to undefined method Illuminate\Database\Query\Builder::Module()

Details

Issue is in this Query part ->with('RoleBasedPermissions.Permission.Module')

Am I missing something?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire