在航行管理员的字符串上调用成员函数RelationLoaded() [英] Call to a member function relationLoaded() on string on voyage admin

查看:133
本文介绍了在航行管理员的字符串上调用成员函数RelationLoaded()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从此处成功安装了voyager管理员

I installed the voyager admin successfully from here

在我的客户页面上,我创建了一个从auth派生的自定义注册.我可以成功注册用户.

On my client page, I created a custom registration which is derived from auth. I can register the user successfully.

在安装了voyager admin之后,我在客户的注册表单上添加了一个新用户.然后,当我尝试访问http://localhost:8000/admin时,如图所示,发生了错误.

After I installed the voyager admin, I added a new user on client's registration form. Then, when i tried to access the http://localhost:8000/admin and then error occurred as seen on the image.

下面是第53行的图片:

Below is the image of the line 53:

下面是VoyagerUse.php的整个代码

And below is the entire code of VoyagerUse.php

<?php

namespace TCG\Voyager\Traits;

use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use TCG\Voyager\Facades\Voyager;
use TCG\Voyager\Models\Role;

/**
 * @property  \Illuminate\Database\Eloquent\Collection  roles
 */
trait VoyagerUser
{
public function role()
{
    return $this->belongsTo(Voyager::modelClass('Role'));
}

/**
 * Check if User has a Role(s) associated.
 *
 * @param string|array $name The role to check.
 *
 * @return bool
 */
public function hasRole($name)
{
    if (!$this->relationLoaded('role')) {
        $this->load('role');
    }

    return in_array($this->role->name, (is_array($name) ? $name : [$name]));
}

public function setRole($name)
{
    $role = Voyager::model('Role')->where('name', '=', $name)->first();

    if ($role) {
        $this->role()->associate($role);
        $this->save();
    }

    return $this;
}

public function hasPermission($name)
{
    if (!$this->relationLoaded('role')) {
        $this->load('role');
    }

    if (!$this->role->relationLoaded('permissions')) {
        $this->role->load('permissions');
    }

    return in_array($name, $this->role->permissions->pluck('key')->toArray());
}

public function hasPermissionOrFail($name)
{
    if (!$this->hasPermission($name)) {
        throw new UnauthorizedHttpException(null);
    }

    return true;
}

public function hasPermissionOrAbort($name, $statusCode = 403)
{
    if (!$this->hasPermission($name)) {
        return abort($statusCode);
    }

    return true;
}
}

推荐答案

如VoyagerUser第53行所述:

As mentioned in the VoyagerUser in line 53 :

if(!$this->role->relationLoaded('permissions')){ ...

此处的角色被视为关系而非字段:)

The role here is considered as a relation not a field :)

和错误

在字符串上调用成员函数RelationLoaded()

Call to a member function relationLoaded() on string

表示您在用户模型中具有作为属性的角色

means that you have the role as attribute in the User Model

因此,您要做的就是将角色属性重命名为其他名称,一切都会正常运行;)

So all you have to do is rename the role attribute to something else and everything will work perfectly ;)

这篇关于在航行管理员的字符串上调用成员函数RelationLoaded()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆