/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $rule = ['degree_name' => 'required | min: 3']; $this->validate($request, $rule); $degree = new Degree($request->all()); $degree->save(); return redirect('/admin/degree/create')->with('status', 'Degree saves successfully'); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ public function create(array $data) { $user = User::create(['first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'phone_number' => $data['phone_number'], 'number_of_degrees' => $data['num_degrees']]); $user->save(); $num_degree_str = ['one', 'two', 'three', 'four']; for ($i = 0; $i < $data['num_degrees']; $i++) { $degree = new Degree(); $degree->year = $data['degree_year_' . $num_degree_str[$i]]; $degree->user_id = $user->id; $degree->faculty = $data['degree_faculty_' . $num_degree_str[$i]]; $degree->type = $data['degree_type_' . $num_degree_str[$i]]; if ($i == 0) { $degree->primary_degree = true; } else { $degree->primary_degree = false; } $degree->save(); } return $user; }
/** * Run the database seeds. * * @return void */ public function run() { $url = "https://randomuser.me/api/?results=50&key=" . env('RANDOMUSER_API_KEY') . "&nat=us"; $json = file_get_contents($url); $json_data = json_decode($json, true); file_put_contents('current_userset.txt', $json); foreach ($json_data['results'] as $result) { $user = new User(); $user->email = $result['user']['email']; $user->password = bcrypt($result['user']['password']); $user->first_name = ucfirst($result['user']['name']['first']); $user->last_name = ucfirst($result['user']['name']['last']); $user->phone_number = $result['user']['phone']; $user->number_of_degrees = 1; $user->save(); $degree = new Degree(); $degree->year = rand(1923, 2010); $degree->user_id = $user->id; $faculties = array('arts_and_science', 'education', 'engineering_and_applied_science', 'health_science', 'law', 'business', 'graduate_studies', 'policy_studies'); $types = array('ba', 'bcmp', 'bfa', 'bphe', 'bs', 'bsce', 'bcomm', 'msc', 'phd'); $degree->faculty = $faculties[array_rand($faculties)]; $degree->type = $types[array_rand($types)]; $degree->primary_degree = true; $degree->save(); $pictureUploadResult = \Cloudinary\Uploader::upload($result['user']['picture']['large']); if ($pictureUploadResult == null) { echo "Error uploading picture for " . $result['user']['name']['first'] . $result['user']['name']['last']; continue; } $picture = new Picture(); $picture->description = ""; $picture->url = $pictureUploadResult['secure_url']; $picture->cloudinary_public_id = $pictureUploadResult['public_id']; $picture->save(); $junction = new UserPictureBridge(); $junction->user_id = $user->id; $junction->picture_id = $picture->id; $junction->save(); } }
$degree->delete(); } /* Recreate the degrees in the same way as AuthController */ $num_degree_str = ['one', 'two', 'three', 'four']; for ($i = 0; $i < $data['num_degrees']; $i++) { $degree = new Degree(); $degree->year = $data['degree_year_' . $num_degree_str[$i]]; $degree->user_id = $user->id; $degree->faculty = $data['degree_faculty_' . $num_degree_str[$i]]; $degree->type = $data['degree_type_' . $num_degree_str[$i]]; if ($i == 0) { $degree->primary_degree = true; } else { $degree->primary_degree = false; } $degree->save(); } return redirect(url('profile')); })); Route::post('/property/add/photo', function (Request $request) { $validator = Validator::make($request->all(), ['property_id' => 'required|numeric|min:0|integer', 'image' => 'required|image']); if ($validator->fails()) { return redirect(url('/property/add/photo/' . $request->property_id))->withInput()->withErrors($validator); } $pictureUploadResult = \Cloudinary\Uploader::upload($request->image); if ($pictureUploadResult == null) { $errorArr = array("The image upload service is down, sorry!"); return redirect(url('/property/add/photo/' . $request->property_id))->withInput()->withErrors($errorArr); } $picture = new Picture(); // TODO: Get an (optional) description from users?