简体   繁体   中英

DB::select procedure return empty array from input request

I created this function in my controller:

public function productInvoiceListTest(Request $request){
    $var = $request->client_id;
    $date = "2019-12-30";

    $sql = 'CALL proc_invoice_product_list("'.$var.'","i.invoice_date","2019-12-30","","")';

    $productinvoice = DB::select($sql);
    var_dump($productinvoice);
}

When i run the code its return empty array, but when i hardcode value of $var it works:

public function productInvoiceListTest(Request $request){
    $var = 'dasdsdasdsadsadsa';
    $date = "2019-12-30";

    $sql = 'CALL proc_invoice_product_list("'.$var.'","i.invoice_date","2019-12-30","","")';

    $productinvoice = DB::select($sql);
    var_dump($productinvoice);
}

Why when i use input from request can't call my procedure? How do i read from input request?

You may need to first confirm the client_id is being passed to your productInvoiceListTest method by using the dd helper.

public function productInvoiceListTest(Request $request){
    dd($request->all());
}

If the client_id is part of the the request instance passed in your productInvoiceListTest method, then you can access it using $request->input('client_id') method. If it is not part of the request instance, ensure that from the method calling or redirecting to productInvoiceListTest , the client_id is passed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM