[Vuejs]-How to pass simple user input from Vue to Laravel Controller?

0๐Ÿ‘

โœ…

I was able to send data back and forth using axios

Here is what I had for my Vue Component:

<template> ... </template>
<script>
    export default {
    data() {
        return {
            name: '',
            days: ''
        }
    },
    methods: {
        getData() {
            axios.get('/api/urihere', {
                params: {
                    name: this.name,
                    days: this.days
                }
            }).then((response) => {
                console.log(response.data)
            }).catch((error) => {
                console.log(error)
            })
        }
      
    },
    mounted() {
        // 
    }
}

</script>

While I had you had a simple get for Routes

Route::get('/urihere', [UrihereController::class, 'someMethod']);

and inside the said-controller

public function someMethod(Request $request)
{
    return [$request->name, $request->days];
}

0๐Ÿ‘

Have you heard of inertiajs?

inertiajs allows you to create fully client-side rendered, single-page apps, without much of the complexity that comes with modern SPAs. It does this by leveraging existing server-side frameworks.

Leave a comment