In this example, to insert data to our table, we use axios to make POST request to our API with json object data. Example structure of our object as illustrates

The data object is passed from our front end form to our store.js. In our store.js, inside our actions
let { data } = await Axios.post('http://localhost:8888/test/public/api/learners', { body: learnerdetail });
When the object received by the controller, it will pass to the appropriate method which in this case is store method().
public function store(Request $request) { $learner = new Learner(); $learner->name = $request->input('body.name'); $learner->learner_id = $request->input('body.learner_id'); $learner->section = $request->input('body.section'); $learner->save(); //return $learner; }
Leave a Reply