Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shahr's avatar
Level 10

How to get response data in console?

I want to get warranty_id and product_id and date

blade.php

<script>
    let product_id = "{{ $product->id}}";
    let warranty_id= "{{ $warranty->id}}";
    const app = new Vue({
        el: '#app',
        data: {
            dates: [],
            products: [],
            warranties: [],
            date: '',
            product_id:  product_id ,
            warranty_id: warranty_id,
        },
        watch: {
            date(newDate) {
                const showType = document.getElementById('showType');
                showType.textContent = newDate;
                axios.get('{{ route('product.warranty.save') }}', {
                    date: newDate,
                    product_id: this.product_id,
                    warranty_id: this.warranty_id,
                })
                    .then(response => {
                        console.log('get Response---->: ', response);
                    })
                    .catch(error => {
                        console.log('Error:', error);
                    });
            }
        },
        components: {
            DatePicker: VuePersianDatetimePicker
        }
    });
</script>

web.php

Route::get('products/warranties/save', [App\Http\Controllers\Admin\WarrantyController::class, 'save'])->name('product.warranty.save');

WarrantyController.php

public function save(Request $request)
{
    $product_id = $request->post('product_id');
    $warranty_id = $request->post('warranty_id');
    $date = $request->post('date');
    return response()->json([
        
    ]);
}
0 likes
1 reply
LaryAI's avatar
Level 58

To get the response data in the console, you can simply log the response object in the console using console.log(response.data). This will log the data returned by the server in the console.

Here's the updated code:

watch: {
    date(newDate) {
        const showType = document.getElementById('showType');
        showType.textContent = newDate;
        axios.get('{{ route('product.warranty.save') }}', {
            date: newDate,
            product_id: this.product_id,
            warranty_id: this.warranty_id,
        })
            .then(response => {
                console.log('get Response---->: ', response.data);
            })
            .catch(error => {
                console.log('Error:', error);
            });
    }
},

This will log the warranty_id, product_id, and date in the console. You can then use this data as required.

Please or to participate in this conversation.