Please format you code and place it between three backticks `
Much easier to read.
SELECT *
FROM table
WHERE col1 = 'Value';
im new in laravel and tring to create eloquent builder from query string using laravel 12 i have this query, it works fine and get the data i need
SELECT cComPPresentacion, cComProveedor, cComPPrecio
FROM tComPartidas AS Par JOIN tCompras ON cComId = cComPCompra
WHERE DATE_FORMAT(cComRecibida, '%Y-%m-%d') BETWEEN '20201201' AND '20211231'
AND cComPRecibido = cComPRequerido
AND cComPPrecio =
(SELECT MIN(cComPPrecio)
FROM tComPartidas AS Min JOIN tCompras ON cComId = cComPCompra
WHERE Min.cComPPresentacion = Par.cComPPresentacion
AND cComPRecibido = cComPRequerido
AND DATE_FORMAT(cComRecibida, '%Y-%m-%d') BETWEEN '20201201' AND '20211231'
so far i got this
PurchaseItemsModel->whereColumn("needed", "recieved")
->whereHas("purchase", function($query){
$query->whereRaw("DATE_FORMAT('recievedDate', '%Y-%m-%d') BETWEEN '2020-01-01' AND '2021-12-31'");
->where("precio", function($query){
//something
});
but dont know how to do this
AND cComPPrecio =
(SELECT MIN(cComPPrecio)
FROM tComPartidas AS Min JOIN tCompras ON cComId = cComPCompra
WHERE Min.cComPPresentacion = Par.cComPPresentacion
AND cComPRecibido = cComPRequerido
AND DATE_FORMAT(cComRecibida, '%Y-%m-%d') BETWEEN '20201201' AND '20211231')
into this
->where("cComPPrecio ", function($query){
//how call this comparision from new select with parent
WHERE Min.cComPPresentacion = Par.cComPPresentacion
})
this function works fine using DB::select but want to do it with query builder
also have a similar question on eloquent relations like this
public function Parent(){
return $this->hasOne("App\Models\ClientsModel", "cCliSecuencia", "cCliSecuencia")
->where("cCliSecuencia", $this->cCliSecuencia)
->where("cCliSecuenciaEncadenado", 0)
->where("cCliID", "!=", $this->cCliID);
}
when call like
$model->with("parent")->get();
, i cant get the attributes from $this but calling like this way, it get the data propertly.
$data = $model->get();
foreach($data as $key => $value)
$value->parent;
thanks in advance for your help, i really apreciate it
Please or to participate in this conversation.