mercredi 6 mars 2019

Eloquent way to perform text search text on given ids only

I have a table with two columns that contain some text data. What i want to do is to search these columns but only for the given ids. So far the i am getting the result for the whole db disregarding the ids supplied. This is because orwhere condition is set up wrong. I cannot figure out how to set up properly

   $qu = \App\AppModels\Quotation::with([
        'products.product',
        'paymentTerms',
        'deliveryTerms',
        'company',
        'status',
        'createdByUser'
    ]);


    if($search_q){
        $qu->where( 'name', '=', $search_q )
        ->orWhere( 'reference', '=', $search_q )
        ->orWhere( 'name', 'LIKE', '%' . $search_q )
        ->orWhere( 'name', 'LIKE', '%' . $search_q . '%' )
        ->orWhere( 'name', 'LIKE', $search_q . '%' )
        ->orWhere( 'reference', 'LIKE', '%' . $search_q )
        ->orWhere( 'reference', 'LIKE', '%' . $search_q . '%' )
        ->orWhere( 'reference', 'LIKE', $search_q . '%' );
    }

    $quotations = $qu->where('created_at', '>=', $records_from)
    ->whereIn('id',array_unique($quotation_ids))
    ->orderBy('created_at','DESC')
    ->get();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire