laravel getNameAttribute不适用于搜索

我有帐户模型 而且我里面有这个方法..

public function getNameAttribute()
{
    if(\App::getLocale() == 'en')
        return $this->attributes['foreign_name'];
    else
        return $this->attributes['name'];
}

in the index page its working if the locale is en the name will be the foreign_name like this picture enter image description here but i have search method and this is the code

public static function search_and_select($keyword)
{
    $keyword = Helper::clean_keyword($keyword);
    $data = Account::where
    ('number','like','%'.$keyword.'%')->
    orWhere('name','like','%'.$keyword.'%')->
    limit(30)->
    get(['user_id','number','name']);
    if(count($data) == 0)
        return Helper::no_result();
    return [$data,['number','name']];       
}

如果我尝试搜索任何有关此错误的信息

message: "Undefined index: foreign_name"
    1: {,…}
class: "App\Models\Account"
file: "C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php"
function: "getNameAttribute"
line: 465
type: "->"
2: {,…}
class: "Illuminate\Database\Eloquent\Model"
file: "C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php"
function: "mutateAttribute"
line: 479
type: "->"

但是如果我改变

return $this->attributes['foreign_name'];

return $this->attributes['id']; // or any integer field in the accounts table its working without problem 

与laravel 6它正在与我一起工作,但现在我盖特这个错误 任何帮助在这里..

评论
in_ut
in_ut

多少钱?

Vital alpha testo The Diet Solution is priced at an affordable $39.Ninety seven for a 95 page printable e-direction. The Platinum upgrade bundle for $20 consists of One on One Coaching immediately with Isabel,

饮食解决方案将如何?

Primal grow pro There is now available a FREE Trial of The Diet Solution Program. Her Quick Start Guide helps You stand up and walking inside minutes. Solid technology at the back of her teaching, defined in ordinary language. How eating good stuff improves coronary heart, organs, and usual health.

点赞
评论