Skip to content

Commit d02a82f

Browse files
committed
edit student
1 parent a568cdc commit d02a82f

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

app/Http/Controllers/StudentController.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
class StudentController extends Controller
99
{
10-
public function save_student(){
10+
public function save_student()
11+
{
1112
$student = new Student;
1213
$student->name = request()->name;
1314
$student->email = request()->email;
@@ -16,15 +17,25 @@ public function save_student(){
1617
return 'fersgdre';
1718
}
1819

19-
public function all_students(){
20+
public function all_students()
21+
{
2022
$students = Student::paginate(5);
2123
return response()->json($students);
2224
}
23-
public function edit_student($id){
25+
26+
public function edit_student($id)
27+
{
2428
$student = Student::find($id);
2529
return response()->json($student);
2630
}
27-
public function update_student(){
28-
return 'test';
31+
32+
public function update_student()
33+
{
34+
$student = Student::find(request()->id);
35+
$student->name = request()->name;
36+
$student->email = request()->email;
37+
$student->phone = request()->phone;
38+
$student->update();
39+
return 'done update';
2940
}
3041
}

public/js/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ __webpack_require__.r(__webpack_exports__);
21412141
edit_name: "",
21422142
edit_email: "",
21432143
edit_phone: "",
2144-
id: ''
2144+
id: ""
21452145
};
21462146
},
21472147
mounted: function mounted() {
@@ -2181,6 +2181,7 @@ __webpack_require__.r(__webpack_exports__);
21812181
updateStudent: function updateStudent() {
21822182
console.log(this.id);
21832183
axios.put("update_student", {
2184+
id: this.id,
21842185
name: this.edit_name,
21852186
email: this.edit_email,
21862187
phone: this.edit_phone

resources/js/components/CreateComponent.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export default {
187187
edit_email: "",
188188
edit_phone: "",
189189
190-
id: '',
190+
id: "",
191191
};
192192
},
193193
mounted() {
@@ -220,14 +220,16 @@ export default {
220220
this.edit_phone = response.data.phone;
221221
});
222222
},
223-
updateStudent(){
223+
updateStudent() {
224224
console.log(this.id);
225-
axios.put("update_student" , {
226-
name: this.edit_name,
227-
email: this.edit_email,
228-
phone: this.edit_phone,
229-
})
230-
.then(response => console.log(response));
225+
axios
226+
.put("update_student", {
227+
id: this.id,
228+
name: this.edit_name,
229+
email: this.edit_email,
230+
phone: this.edit_phone,
231+
})
232+
.then((response) => console.log(response));
231233
},
232234
},
233235
};

routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
Route::post('save_student', 'StudentController@save_student');
2222
Route::get('all_students', 'StudentController@all_students');
2323
Route::get('edit_student/{id}', 'StudentController@edit_student');
24-
Route::get('update_student', 'StudentController@update_student');
24+
Route::put('update_student', 'StudentController@update_student');

0 commit comments

Comments
 (0)