From 41c8f50e28ab7f3275a065f00ba6982680dcb3e6 Mon Sep 17 00:00:00 2001 From: joynalam67598 <59138477+joynalam67598@users.noreply.github.com> Date: Wed, 22 Sep 2021 13:27:58 +0600 Subject: [PATCH 1/2] complete save and load table functionalities --- .idea/codeStyles/codeStyleConfig.xml | 5 + .../inspectionProfiles/profiles_settings.xml | 5 + .idea/modules.xml | 8 ++ .idea/react-crud-with-laravel.iml | 126 ++++++++++++++++++ .idea/vcs.xml | 6 + .../Controllers/API/StudentController.php | 19 ++- laravelapi/routes/api.php | 6 + react-crud-app/src/App.js | 2 + .../src/components/pages/AddStudent.js | 14 +- .../src/components/pages/EditStudent.js | 125 +++++++++++++++++ .../src/components/pages/Student.js | 51 ++++++- 11 files changed, 363 insertions(+), 4 deletions(-) create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/react-crud-with-laravel.iml create mode 100644 .idea/vcs.xml create mode 100644 react-crud-app/src/components/pages/EditStudent.js diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..df5f35d --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..0eefe32 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..fc113aa --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/react-crud-with-laravel.iml b/.idea/react-crud-with-laravel.iml new file mode 100644 index 0000000..8fd626a --- /dev/null +++ b/.idea/react-crud-with-laravel.iml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..9661ac7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/laravelapi/app/Http/Controllers/API/StudentController.php b/laravelapi/app/Http/Controllers/API/StudentController.php index b733b17..98f91bd 100644 --- a/laravelapi/app/Http/Controllers/API/StudentController.php +++ b/laravelapi/app/Http/Controllers/API/StudentController.php @@ -8,7 +8,24 @@ class StudentController extends Controller { - public function store(){ + public function store(Request $request){ $student = new Student(); + $student->name= $request->name; + $student->course= $request->course; + $student->email= $request->email; + $student->phone= $request->phone; + $student->save(); + return response()->json([ + "status"=> 200, + "message"=>"Student Save Successfully" + ]); + } + + public function index(){ + $students = Student::all(); + return response()->json([ + "status"=> 200, + "students"=>$students + ]); } } diff --git a/laravelapi/routes/api.php b/laravelapi/routes/api.php index eb6fa48..9559b62 100644 --- a/laravelapi/routes/api.php +++ b/laravelapi/routes/api.php @@ -2,6 +2,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; +use App\Http\Controllers\API\StudentController; /* |-------------------------------------------------------------------------- @@ -13,6 +14,11 @@ | is assigned the "api" middleware group. Enjoy building your API! | */ + // data send er jonno post; + Route::post("/add-student",[StudentController::class,'store']); + Route::get("/all-students",[StudentController::class,'index']); + + Route::middleware('auth:sanctum')->get('/user', function (Request $request) { return $request->user(); diff --git a/react-crud-app/src/App.js b/react-crud-app/src/App.js index ddcb8c4..0bbc22d 100644 --- a/react-crud-app/src/App.js +++ b/react-crud-app/src/App.js @@ -2,6 +2,7 @@ import { BrowserRouter as Router, Route, Switch } from "react-router-dom"; import "./App.css"; import AddStudent from "./components/pages/AddStudent"; import Student from "./components/pages/Student"; +import EditStudent from "./components/pages/EditStudent"; function App() { return ( @@ -9,6 +10,7 @@ function App() { + ); diff --git a/react-crud-app/src/components/pages/AddStudent.js b/react-crud-app/src/components/pages/AddStudent.js index 2ccf601..2bd13fe 100644 --- a/react-crud-app/src/components/pages/AddStudent.js +++ b/react-crud-app/src/components/pages/AddStudent.js @@ -1,6 +1,7 @@ import axios from "axios"; import { useState } from "react"; import { Link } from "react-router-dom"; +import React from 'react'; export default function AddStudent() { const [studentData, setStudentData] = useState({ @@ -18,9 +19,18 @@ export default function AddStudent() { }; const saveStudent = async (e) => { - e.prventDefault(); + e.preventDefault(); try { - const res = await axios.post("/api/add-student", studentData); + const res = await axios.post("http://localhost:8000/api/add-student", studentData); + if(res.data.status===200) { + console.log(res.data.message); + setStudentData({ + name: "", + course: "", + email: "", + phone: "", + }) + } } catch (err) { console.log(err); } diff --git a/react-crud-app/src/components/pages/EditStudent.js b/react-crud-app/src/components/pages/EditStudent.js new file mode 100644 index 0000000..6d64ee0 --- /dev/null +++ b/react-crud-app/src/components/pages/EditStudent.js @@ -0,0 +1,125 @@ +import axios from "axios"; +import { useState,useEffect } from "react"; +import { Link } from "react-router-dom"; +import {useParams} from 'react-router'; +import React from 'react'; + +export default function EditStudent() { + const [studentData, setStudentData] = useState({ + name: "", + course: "", + email: "", + phone: "", + }); + const {id} = useParams(); + + + let name, value; + const handleChange = (e) => { + name = e.target.name; + value = e.target.value; + setStudentData({ ...studentData, [name]: value }); + }; + + useEffect(()=>{ + async function getStudent(){ + const res = await axios.get(`api/editStudent/${id}`) + if(res.data.status == 200) + { + + } + + } + getStudent(); + },[id]) + + const updateStudent = async (e) => { + e.preventDefault(); + try { + const res = await axios.post("http://localhost:8000/api/update-student", studentData); + if(res.data.status===200) { + console.log(res.data.message); + setStudentData({ + name: "", + course: "", + email: "", + phone: "", + }) + } + } catch (err) { + console.log(err); + } + }; + + return ( +
+
+
+
+
+

+ Add Student + + Back + +

+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+
+ ); +} diff --git a/react-crud-app/src/components/pages/Student.js b/react-crud-app/src/components/pages/Student.js index b7b2246..0fe2966 100644 --- a/react-crud-app/src/components/pages/Student.js +++ b/react-crud-app/src/components/pages/Student.js @@ -1,6 +1,24 @@ import { Link } from "react-router-dom"; +import axios from "axios"; +import React,{useEffect,useState} from 'react'; export default function Student() { + + const [students, setStudents] = useState([]); + const [loading, setLoading] = useState(true); + + useEffect(() =>{ + async function fetchData(){ + setLoading(true); + const res = await axios.get('http://localhost:8000/api/all-students'); + if(res.data.status===200){ + setStudents(res.data.students); + setLoading(false); + } + } + fetchData(); + },[]); + return (
@@ -17,7 +35,38 @@ export default function Student() {
-
+
+ + + + + + + + + + + + + {loading && } + {!loading && ( + students.map((student) => + + + + + + + + + )) + } + +
IdNameCourseEmailPhoneAction
Loading...
{student.id}{student.name}{student.course}{student.email}{student.phone} + Edit + Delete +
+
From d1cb29d82841aa7f225a71d278ddcef34572bd83 Mon Sep 17 00:00:00 2001 From: joynalam67598 <59138477+joynalam67598@users.noreply.github.com> Date: Wed, 22 Sep 2021 13:29:45 +0600 Subject: [PATCH 2/2] complete save and load data functionalities --- .idea/.gitignore | 8 ++ .idea/inspectionProfiles/Project_Default.xml | 15 +++ .idea/misc.xml | 6 + .idea/php.xml | 124 +++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/php.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..725346b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../../:\xampp\htdocs\react-crud-with-laravel\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..21d55c8 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d9fdae0 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..3b86de5 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file