[Vuejs]-How to load data based on id using Vue js and Laravel?

0👍

You can use a relationship on the CandidateProfile model. See here https://laravel.com/docs/7.x/eloquent-relationships. So for example with user you can have in you CandidateProfile model

public function user()
{
    // You can choose the relationship that best suits your need for the users table
    return $this->belongsTo(User::class);
}

and when querying you can get that relationship by

 $candidateProfile = CandidateProfile::with('users')->orderBy('created_at', 'asc')->paginate(5);

then you can access those users by

$candidateProfile->users

The same can be applied to your other table relations (video, resumes, photos).

Then you can just pass $candidateProfile back through to your vue js

Leave a comment