【发布时间】:2019-08-28 22:06:51
【问题描述】:
我正在尝试在学生表中插入一个讲座 ID。我需要将学生的 ID 以及讲座的 ID 传递给控制器。我正在使用 axios 将 2 个参数发布到控制器。我的代码不起作用,我做错了吗? Laravel 中的新功能。谢谢
Vue 组件
<a href="" @click="setLectureFK(student.student_id)"><i class="fas fa-user-plus"></i></a>
<script>
export default {
data () {
return {
student:'',
lecture_id:this.$route.params.id,
}
},
methods:{
setLectureFK($student_id){
axios.post('/api/internship/setLecture/'+$lecture_id,'/'+$student_id);
}
},
}
控制器
public function setLecture($lecture,$student)
{
$student = student::findOrFail($student);
$student->lecture_id_FK = $lecture;
$student->save();
}
API.PHP
Route::post('internship/setLecture/{lecture}/{student}', 'API\InternshipController@setLecture')->name('internship.setLecture');
【问题讨论】:
-
那你有什么问题?
-
@ashokpoudel 它不起作用。我认为我犯了错误。
标签: php laravel eloquent axios