0👍
If I understood your question correctly, you want the Student ID returned from the index
method in your controller?
If so, you need to do it like this in your controller:
public function index($id)
{
$student = Student::with(['sectionSubjects','sectionSubjects.section',
'sectionSubjects.subject'])->findOrFail($id);
return [
'student_id' => $id,
'reservations' => $student->sectionSubjects
];
}
and to retrieve the Student ID on your JS like this:
methods: {
fetchSubjects: function() {
var self = this;
this.$http({
url: 'http://localhost:8000/reservation/id/student',
method: 'GET'
}).then(function (response) {
this.$set('studentId', response.student_id); // <-- change here
this.$set('reservations', response.reservations.data); // <-- change here
console.log('success');
}, function (response) {
console.log('failed');
});
}
}
- [Vuejs]-Loading JSON data in Datatable takes too long
- [Vuejs]-The use of bidirectional binding of components in Vue.js
Source:stackexchange.com