模型自定义了方法
假如我在模型自定义了2个方法
class BaseModel extends Model implements CacheableInterface
{
use Cacheable;
public $timestamps = false;//关闭自动写入时间戳
public string $alias = '';
public function withSearch(array $data, array $where = [], array $ignore = ['all'])
{
$builder= $this->xxxx();
return $builder;
}
public function alias($alias)
{
$this->alias = $alias;
return $this->from($this->getTable() . ' as ' . $alias);
}
}
$a = (new mode())->alias('a')->withSearch();
这个时候就会提示 Builder 找不到 withSearch, 所以我改成了
假如我在模型自定义了2个方法
class BaseModel extends Model implements CacheableInterface
{
use Cacheable;
public $timestamps = false;//关闭自动写入时间戳
public string $alias = '';
public function withSearch(array $data, array $where = [], array $ignore = ['all'])
{
$builder= $this->xxxx();
return $builder;
}
public function alias($alias)
{
$this->alias = $alias;
$this->from($this->getTable() . ' as ' . $alias);
return $this;
}
}
$a = (new mode())->alias('a')->withSearch();
这样的话 from 就无法生效了
推荐文章: