Ad

How To Call Laravel Store Procedure Passing With Multipal Values In One Variable

I am using MS-SQL In My Laravel web site and I have create a SP which get result based on filter type It working fine when i Run The SP on MS-SQL ( http://prntscr.com/k70ta9 ) e.g : exec GetInventoryDetail @site='MI,SI' ( it return more then 100 Records )

Now the problem is when i send request by ajax it return zero result for "site" and "readyDate" In these two variables we have to pass more then two values like : 'MI,SI,DC' etc.

Please have a look on screen-short : http://prntscr.com/k70o7q

And My Function is which handle request is under given.

public function inventoryDetailData(Request $request){

    try{

            $vendorId   =   ($request->vendorId)? $request->vendorId : "";
            $site       =   ($request->site)?  $request->site  : "";
            $readyDate  =   ($request->readyDate)? $request->readyDate : "";


    $filterArray    = array($vendorId,$site,$readyDate);

    $result =   DB::select('exec GetInventoryDetail ?,?,?,', $filterArray);

    dd($result);

    }
    catch(\Exception $e){

        return response()->json(['status' => 'danger','message' => $e->getMessage()]);  

    }

This ajax functionality works fine for vendorId only but not for others.

Please help me how i can fix this issue. Is there any syntax problem in my code ?

Ad

Answer

I got Solution of my problem I use under given code and it work for me :)

DB::select(DB::raw("exec GetInventoryDetail :Param1, :Param2"),[
                    ':Param1' => $param_1,
                    ':Param2' => $param_2,
                ]);
Ad
source: stackoverflow.com
Ad