/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // store new student $student = new \ATC\Student(); // attempt validation if ($student->validate($request)) { $student->initials = $request->initials; $student->external_id = $request->external_id; $student->save(); // insert new student in table return redirect()->action('StudentController@show', [$student]); } else { $errors = json_decode($student->getErrors()); Session::flash('flash_message', $errors); return back()->withInput(); } }
/** * Run the database seeds. * * @return void */ public function run() { $student = new \ATC\Student(); $student->initials = 'JAM'; $student->external_id = '*****@*****.**'; $student->save(); // number of records to create $numRows = 20; // create Faker object $faker = Faker::create(); for ($i = 0; $i < $numRows; $i++) { // create model object $student = new \ATC\Student(); $student->initials = $faker->unique()->regexify('[A-Z][a-z][A-Z]'); $student->external_id = $faker->unique()->numberBetween(10000000, 99999999); $student->save(); // insert new student in table } }