簡體   English   中英

將數據庫列中的數組與laravel中的另一個數據庫表列進行匹配

[英]match the array from DB column with another DB table column in laravel

我通過數組(如地址)的形式通過2表獲取數據,並在另一個表中找到特定的密碼,這里是我用來查找和匹配結果並執行例如tax功能的2模型。 如果一個表的數組為ab,c,d,第二個表的值為要在其中查找值的存儲。 如果a = 1如果b = 2這樣,這是我的代碼想法,試圖實現但沒有成功

    try
    {    
    $toltax = toltax::wheresource('LIKE','%'.$s_address.'%')->get();
    $tsource = $toltax->source;
    $tdestination = $toltax->destination;
    if(!empty($toltax = toltax::where($s_address, 'LIKE' ,"%$tsource%")
                                ->where($d_address,'LIKE',"%$tdestination%")
                                ->get('tax')
            )
    ){
        Log::info("toll tax".$toltax->tax);
        $Tax = $Tax + $toltax->tax;
    }
}catch(ModelNotFoundException $e) {
    return false;
}

試試這個,希望對你有幫助

$tax = DB::table('toltax as latest')
        ->whereSource('LIKE','%'.$s_address.'%')
        ->whereNotExists(function ($query) {
            $query->select(DB::raw(1))
                   ->from('toltax')
                   ->whereRaw('source LIKE latest.source')
                   ->whereRaw('destination LIKE latest.destination');
        })
    ->get(['tax']);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM