【发布时间】:2016-09-25 22:02:53
【问题描述】:
我在使用 vue js 时获取嵌套资源的 uri 时遇到问题。请参阅下面的代码。
ReservationController.php
public function index($id)
{
$student = Student::with(['sectionSubjects','sectionSubjects.section',
'sectionSubjects.subject'])->findOrFail($id);
return $student->sectionSubjects;
}
all.js
methods:{
fetchSubjects: function(){
var self = this;
this.$http({
url: 'http://localhost:8000/reservation/id/student',
method: 'GET'
}).then(function (reservations){
this.$set('reservations', reservations.data);
console.log('success');
}, function (response){
console.log('failed');
});
}
}
这里的问题是,获取这个urlhttp://localhost:8000/reservation/id/student的id的值。有没有办法获取 index() 方法的参数的 id?这也是我的路线列表http://imgur.com/8MWaCpO
【问题讨论】:
-
您的应用需要知道您尝试向其发送请求的 ID,因此您需要通过 http 请求获取预订。
-
@Jeff 是的,这是我的问题,我无法在获取 uri 之前找到获取该 ID 的方法。你能给我举个例子吗?
标签: laravel laravel-5 laravel-5.1 laravel-5.2 vue.js