Example #1
0
function get_thumbnail_from_user_id($user_id)
{
    $profile_pics = UserPictureBridge::where('user_id', $user_id)->get();
    if (count($profile_pics) < 1) {
        $placeholder = new Picture();
        $placeholder->url = env('PLACEHOLDER_PROFILE_PIC_URL');
        $placeholder->cloudinary_public_id = env('PLACEHOLDER_PROFILE_PIC_PUBLIC_ID');
        return $placeholder;
    } else {
        return Picture::find($profile_pics[0]->picture_id);
    }
}
 /**
  * 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();
     }
 }