This means that there's a job without user.
user console.log for response.data.jobs and see if every single job has an user
i'm using vuejs plugin pagination for paginate the list but getting error
You can see this
Cannot read property "first name" undefined
my vue js code is
<table v-if="type=='list'" class="table table-bordered table-hover">
<thead>
<tr>
<th>Title</th>
<th>User</th>
<th>Birth Date</th>
</tr>
</thead>
<tbody>
<tr v-for="(job,key) in jobs">
<td>{{ job.title }}</td>
<td>{{ job.user.first_name }} {{ job.user.last_name }}</td>
<td>{{ job.birt_date | formatDate }}</td>
</tr>
</tbody>
</table>
<pagination :data="jobs" :limit="1" @pagination-change-page="getResults"></pagination>
<script>
Vue.component('pagination', require('laravel-vue-pagination'));
export default {
mounted() {
this.getResults()
},
data(){
return{
csrfToken : Laravel.csrfToken,
title: '',
birt_date: '',
jobs:[],
}
},
methods: {
getResults(page = 1) {
let _this = this;
axios.get('/admin/jobs/create', {
params: {
page: page,
}
})
.then(response => {
_this.jobs = response.data.jobs;
})
.catch(response => {
this.errors = response.errors;
console.log(response);
});
}
}
</script>
laravel code is
$jobs = Job::with('user')->paginate(5);
return response()->json([
'success' => true,
'jobs' => $jobs
]);
Please or to participate in this conversation.