/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //First an empty instance of the object: $student = new Student(); //Then assign the data from the form to that object $student->first = $request->first; $student->last = $request->last; $student->remarks = $request->remarks; //Save the data in the database if (!$student->save()) { $errors = $student->getErrors(); //Redirect back to the create page and pass along the errors return redirect()->action('StudentController@create')->with('errors', $errors)->withInput(); } //Sucessfully created return redirect()->action('StudentController@index')->with('message', '<div class="alert alert-success">Student added successfully</div>'); }