laravel in sapped data with image using ajax


1.blade

<div class="col-sm-6">
    <h3 class="text-dark" id="pname-{{$product_id}}">
        <strong id="product_name"></strong>
    </h3>
    <h3 class="text-warning p-t-30">
        <strong id="product_price"><i class="fa fa-inr"></i></strong>
    </h3>
    <h5 class="text-dark p-t-15">
        <strong id="product_description"></strong>
    </h5>
</div>

<script>
    jQuery(document).ready(function () {

        $.ajax({
            url: "{{route('getCatalogueProduct')}}",
            method: 'GET',
            data: { product_id: '{{ $product_id }}'},
            dataType: 'json',
            success: function (data) {
                var img_id = 'img-{{ $product_id }}';
                var image_url = document.createElement("IMG");
                image_url.setAttribute("src", data.image_url);
                image_url.setAttribute("width", "328");
                image_url.setAttribute("height", "328");
                image_url.setAttribute("class", "img-responsive");
                image_url.setAttribute("alt", data.product_name);
                document.getElementById(img_id).append(image_url);
                document.getElementById("product_name").append(data.product_name);
                document.getElementById("product_description").append(data.product_description);
                document.getElementById("product_price").append(data.price);
            }
        });

    });
</script>


Controller 

public static function getCatalogueProduct(Request $request) {    $productCatalogDetails            = ProductCatalogViewTrait::getCatalogProducts(['product_id' => $request->get('product_id')])[0];    $imageURL                         = ImageHelper::getThumbnailImage($productCatalogDetails->product_id, '31x40', 'product');    $productCatalogDetails->image_url = $imageURL;    return response()->json($productCatalogDetails);}


Traits

public static function getCatalogProducts($where){    $_objProduct_catalog_view = ProductCatalogView::where($where)->get();    return $_objProduct_catalog_view;}




































Popular posts from this blog

Ajax Toggle(on/off) on-click Update

Yii Framework In Update Time View Image In Form