0

I have shown vechicle data just I want to get driver data related to vehicle but unfortuntly i am getting error undefined please help me how can i show into draggablelist thank u ?

Controller

public function index(){

  return $vehicles = Vehicle::with('driver')->get();
   
  
}

template view

<div class="row">
            <div class="col-6">
                <q-card-section>
                    <div class="tw-grid">
                        <div class="tw-col-span-6">
                            <DraggableList
                                v-model="api.drivers"
                                label-key="username"
                                :colors="colors"
                            />
                        </div>
                    </div>
                </q-card-section>
            </div>
        </div>

vue js

export default {
    data () {
        return {

            api: {
                vehicles: [],
                drivers: []
            }
        }
    },
    mounted () {
        this.fetchVehiclesDriver()
    },
    methods: {
        fetchVehiclesDriver () {
            this.$api.get(this.apiRoute('client.vector.driver', {
            }))
                .then(({ data }) => {
                    this.api.vehicles = data.vehicles
                    this.api.drivers  = data.vehicles.driver

                    console.log(data.vehicles.driver) // undefined
                })
        }
    }
}
3
  • If the API doesn't send back data.vehicles.driver then no frontend code will help you fix that. Check that your backend is querying and returning the correct data. Commented Feb 16, 2023 at 18:01
  • Yoduh I am getting json data from back end just I need to get driver related to vehicles Commented Feb 17, 2023 at 5:17
  • 1
    do you know for sure that the data you return from the backend, $vehicles also contains the driver data? if so, you can always check the network tab of your browser's dev tools to see the entire response. if the driver data exists, it'll be there. if you need help figuring out how to extract the data from that JSON, paste the JSON in your question and I can help figure out the correct JS to get to it. Commented Feb 17, 2023 at 15:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.