我通过odbc连接数据库, 它工作正常, 但我必须使用几个搜索标准, 我看到需要通过范围来做.
我可以在控制器中进行查询。
$busqueda_db= DB::connection('odbc')->table('tbl_taller')->select('cod_empresa','nombre_empresa','numero_orden','anio','fecha_liquidacion' , 'estado')->where('cod_empresa',1)->where('estado','activo')->get();
我的想法是调用模型中的函数,就像这样。
public function scopeEmpresa(){
return $this->where('codigo_empresa',2)->get();
}
public function scopeStatus(){
return $this->where('estado','activo')->get();
}
我很感激你的宝贵帮助,但我还是找不到办法。
Mrhn,谢谢,这正是我正在寻找的,但现在我有一个问题,我需要从控制器发送一个变量到模型中的范围,我已经尝试过这样做,但它不工作。
$cod_empresa = $request->get('codigo_empresa');
Taller::empresa($cod_empresa)
->select('cod_empresa','nombre_empresa','numero_orden','anio','fecha_liquidacion' , 'estado')->get();
在模型中,我需要发送一个变量到模型中的范围,我已经尝试过这样做,但它不工作。
public function scopeEmpresa($codigo_empresa){
return $this->where('cod_empresa',$codigo_empresa);
}
我该怎么做,我很感激你的帮助。