Laravel Administrator(frozennode)中的自定义关系结果标签

时间:2015-10-26 00:58:05

标签: php laravel nested administrator

我有一个三级结构,如Category»Subcategory»Product。

使用Frozennode的Laravel管理员,我试图让它在我创建或编辑产品时,我的子类别关系显示如下:

  • 类别1»子类别1
  • 类别1»子类别2
  • ...

目前我正试图以这种方式覆盖products.php的查询:

<?php

namespace BSA\User;

use Illuminate\Database\Eloquent\Model as Eloquent;

class User extends Eloquent
{
    protected $table = 'users';

    protected $fillable = [
        'email',
        'username',
        'password',
        'perm_level',
        'active',
        'active_hash',
        'remember_identifier',
        'remember_token',
    ];

    public function getFullName()
    {
        if (!$this->first_name || !$this->last_name) {
            return null;
        }

        return "{$this->first_name} {$this->last_name}";
    }

    public function getFirstName()
    {
        if (!$this->first_name) {
            return null;
        }

        return "{$this->first_name}";
    }

    public function getLastName()
    {
        if (!$this->last_name) {
            return null;
        }

        return "{$this->last_name}";
    }

    public function getFullNameOrUsername()
    {
        return $this->getFullName() ?: $this->username;
    }

    public function getFirstNameOrUsername()
    {
        return $this->getFirstName() ?: $this->username;
    }

    public function activateAccount()
    {
        $this->update([
            'active' => true,
            'active_hash' => null
        ]);
    }

    public function hasPermission($permission)
    {

        $permission = $permission - 1;

        return (bool) $this->perm_level > $permission;

    }

    public function perm_one()
    {
        return $this->hasPermission(1);
    }

    public function perm_two()
    {
        return $this->hasPermission(2);
    }

    public function perm_three()
    {
        return $this->hasPermission(3);
    }

    public function perm_four()
    {
        return $this->hasPermission(4);
    }

    public function perm_five()
    {
        return $this->hasPermission(5);
    }

    public function perm_six()
    {
        return $this->hasPermission(6);
    }

    public function perm_seven()
    {
        return $this->hasPermission(7);
    }

    public function perm_eight()
    {
        return $this->hasPermission(8);
    }

    public function perm_nine()
    {
        return $this->hasPermission(9);
    }

    public function perm_ten()
    {
        return $this->hasPermission(10);
    }

}

然而,这会在管理员的下拉列表中输出一个空白结果集,我猜是因为'tree'并不真正作为有效的name_field存在。

非常感谢任何帮助。

0 个答案:

没有答案