添加条件,其中为laravel中的突变子
我想为我的突变子添加条件:年龄 这是我的模型:添加条件,其中为laravel中的突变子,laravel,model-view-controller,mutators,Laravel,Model View Controller,Mutators,我想为我的突变子添加条件:年龄 这是我的模型: class Player extends Model { protected $table = 'players'; public $primaryKey ='idplayer'; public $timestamps = false; public function getAgeAttribute() { return Carbon::parse($this->attribut
class Player extends Model
{
protected $table = 'players';
public $primaryKey ='idplayer';
public $timestamps = false;
public function getAgeAttribute()
{
return Carbon::parse($this->attributes['birth'])->age;
}
}
这是我的控制器,我想在这里为我的变异子设定条件
$data = Player::join('posts','idteam','=','id')
->where('age','like','%' . $query . '%')
->get()
Column not found: 1054 Unknown column 'age' in 'where clause'
你不能,真的。至少不是这样。您不能在数据库中不存在的属性中添加条件