代码之家  ›  专栏  ›  技术社区  ›  senty

我可以在查询中使用变异器吗?

  •  1
  • senty  · 技术社区  · 6 年前

    Class Client {
       protected $fillable = ['name', 'age']
    
       public function getIndustryAttribute() {
          // some evaluations;
    
          return "Programmer"
       }
    }
    

    现在,我想用 Client::where('industry', "Programmer")->get() 为了得到价值。这有可能吗?

    请记住,这是一个完全伪代码,以便于解释。我这样做是因为计划失误。。

    1 回复  |  直到 6 年前
        1
  •  2
  •   gbalduzzi    6 年前

    不,你不能那样做。

    对突变子进行评估 之后

    查询时可以做的是定义正确的 scopes .

    推荐文章