mardi 26 janvier 2016

Nested SQL Query in Laravel Controller

I have two queries running in my controller. I need a value from the first query to be passed into the second. I want the result of both these queries sent to my view.

public function jobs()
{


    $query = DB::table("dbQuotes")
        ->leftJoin("dbACT", "dbQuotes.act_id", "=", "dbACT.ID")
        ->leftJoin("dbOpps", "dbQuotes.act_id", "=", "dbOpps.contactID")
        ->leftjoin('dbBids', 'dbQuotes.act_id','=',
            DB::raw('dbBids.quote_id AND dbBids.user_id = '. Auth::user()->id))
        ->where("dbQuotes.active", "=", "1")
        ->select("dbQuotes.*", "dbACT.*", "dbBids.*",
            (DB::raw('date_format(dbQuotes.posted_date, "%d/%m/%Y %H:%i") as posted_date')),
            (DB::raw('date_format(dbOpps.expected_date, "%d/%m/%Y") as expected_date')))
        ->groupBy("dbQuotes.id")
        ->orderBy("posted_date", "desc")
        ->get();

$passinvaluehere = $query->dbQuotes.act_id


    $bids = DB::table("dbBids")

        ->where("quote_id", "=", $passinvaluehere)
        ->get();


    return view('jobs', ['query' => $query,'bids' => $bids]);

}

My query works and the view is established in the correct way if I replace the passed value with a number, i.e "8763". My question is how, within this function, can I pass the value/s of dbQuotes.act_id into this second query?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire