예제 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param StorePhotoRequest $request
  * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
  */
 public function store(StorePhotoRequest $request)
 {
     //TODO
     // Find a safe way to getClientOriginalExtension()
     //Construct file and path info
     $file = $request->file('photo');
     $ext = '.' . $file->getClientOriginalExtension();
     $filename = time() . $ext;
     $basePath = '/uploads/img/' . $filename;
     $thumbPath = '/uploads/img/thumb/' . $filename;
     $localPath = public_path() . $basePath;
     $localThumbPath = public_path() . $thumbPath;
     //DB info
     $mimeType = $file->getClientMimeType();
     $slug = Photo::generateUniqueSlug(8);
     //Save the full image and the thumb to the server
     $imageFull = Image::make($file->getRealPath())->save($localPath);
     $imageThumb = Image::make($file->getRealPath())->widen(400)->save($localThumbPath);
     //Create the DB entry
     $imageStore = Photo::create(['path' => $basePath, 'thumb_path' => $thumbPath, 'mime_type' => $mimeType, 'slug' => $slug]);
     if ($request->ajax()) {
         return response()->json($imageStore);
     } else {
         return redirect()->route('home')->with(['global-message' => 'Uploaded!', 'message-type' => 'flash-success']);
     }
 }
예제 #2
0
 /**
  * A basic test example.
  *
  * @return void
  */
 public function test_a_photo_has_a_path()
 {
     $photo = Photo::create(['path' => '/storage/test.png']);
     $photo = Photo::find(1);
     $path = $photo->path;
     $this->assertequals("/storage/test.png", $path);
 }
예제 #3
0
 /**
  * Handle a registration request for the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function register(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $attributes = $request->only(array('username', 'first_name', 'last_name', 'description', 'email', 'tel_no', 'type', 'password'));
     // Create user.
     $user = $this->create($attributes);
     if ($request->file('image')) {
         //make timestamp and append username for filename
         $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
         $imageFile = Input::file('image');
         $mime = "." . substr($imageFile->getMimeType(), 6);
         //move file to /public/images/
         $filename = $timestamp . '-' . $user->username;
         $photoData = array('fileName' => $filename, 'mime' => $mime);
         $photo = Photo::create($photoData);
         $imageFile->move(public_path() . '/images/uploads/', $filename . $mime);
         //associate the image with the user
         $user->photo_id = $photo->id;
         $user->photo()->associate($photo);
     }
     $user->save();
     // Send confirmation link.
     return $this->sendConfirmationLink($user);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param OrganisationRequest $request
  * @return \Illuminate\Http\Response
  */
 public function store(OrganisationRequest $request)
 {
     /**
      * If Photo is present then
      */
     if ($request->hasFile('photo')) {
         if ($request->file('photo')->isValid()) {
             $photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
             $request->file('photo')->move(public_path('images'), $photoName);
             $photo = Photo::create(['url' => $photoName]);
             $photoId = $photo->id;
         } else {
             return back()->withNotification('Error! Photo Invalid!')->withType('danger');
         }
     } else {
         $photoId = null;
     }
     $slug = slug_for_url($request->name);
     $details = empty($request->details) ? null : $request->details;
     $initials = empty($request->initials) ? null : $request->initials;
     $address = empty($request->address) ? null : $request->address;
     if (Auth::check()) {
         $request->user()->organisations()->create(['name' => $request->name, 'initials' => $initials, 'details' => $details, 'address' => $address, 'photo_id' => $photoId, 'slug' => $slug, 'user_ip' => $request->getClientIp()]);
     } else {
         $user = User::findOrFail(1);
         $user->organisations()->create(['name' => $request->name, 'initials' => $initials, 'details' => $details, 'address' => $address, 'photo_id' => $photoId, 'slug' => $slug, 'user_ip' => $request->getClientIp()]);
     }
     return back()->withNotification('Organisation has been added!')->withType('success');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     \Eloquent::unguard();
     \DB::table('photos')->delete();
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 50; $i++) {
         Photo::create(array('project_id' => $faker->numberBetween(1, 50), 'photoUrl' => $faker->imageUrl(150, 150, 'city')));
     }
 }
예제 #6
0
 public function savePhoto(Request $request)
 {
     $user = $request->get('CurrentUser');
     if ($user != null) {
         $photo64 = $request->json()->get('photo');
         $newPhoto = Photo::create(['user_id' => $user->id, 'photo' => $photo64]);
         return Response::json(['result' => 'success', 'photo' => $newPhoto->id], 200);
     } else {
         return Response::json(['result' => 'failed', 'message' => 'not authenticated']);
     }
 }
예제 #7
0
 /**
  * @param NewsRequest $request
  * @return mixed
  */
 public function store(NewsRequest $request)
 {
     if ($request->hasFile('photo')) {
         if ($request->file('photo')->isValid()) {
             $photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
             $request->file('photo')->move(public_path('images'), $photoName);
             $photo = Photo::create(['url' => $photoName]);
             $slug = slug_for_url($request->title);
             $request->user()->news()->create(['title' => $request->title, 'type' => $request->type, 'description' => $request->description, 'photo_id' => $photo->id, 'slug' => $slug]);
             return back()->withNotification('News has been created!')->withType('success');
         }
     }
 }
예제 #8
0
 /**
  * @param EventsRequest $request
  * @return mixed
  */
 public function store(EventsRequest $request)
 {
     if ($request->hasFile('photo')) {
         if ($request->file('photo')->isValid()) {
             $photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
             $request->file('photo')->move(public_path('images'), $photoName);
             $photo = Photo::create(['url' => $photoName]);
             $slug = slug_for_url($request->name . ' ' . Carbon::parse($request->date)->diffForHumans());
             $request->user()->events()->create(['name' => $request->name, 'date' => $request->date, 'description' => $request->description, 'venue' => $request->venue, 'photo_id' => $photo->id, 'slug' => $slug]);
             return back()->withNotification('Event has been created!')->withType('success');
         }
     }
 }
예제 #9
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(PhotoRequest $request)
 {
     if ($request->hasFile('photo')) {
         if ($request->file('photo')->isValid()) {
             $photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
             $request->file('photo')->move(public_path('images'), $photoName);
             $photo = Photo::create(['url' => $photoName, 'gallery' => 1]);
             return back()->withNotification('Success! Image has been added to gallery.')->withType('success');
         }
         return back()->withNotification('Error! Something went wrong.')->withType('danger');
     }
     return back()->withNotification('Error! Something went wrong.')->withType('danger');
 }
예제 #10
0
 public function upload(Request $request, $id)
 {
     $album = Album::findOrFail($id);
     $files = $request->file();
     $file = $files['files'][0];
     if (!$file->isValid()) {
         return new Response('Invalid Image ' . print_r($files, true), 400);
     }
     $destinationPath = app()->storagePath() . '/photos/';
     $file->move($destinationPath, $file->getFilename());
     $photo = Photo::create(['path' => $destinationPath . $file->getFilename(), 'name' => $file->getClientOriginalName(), 'album_id' => $album->id]);
     $photoArray = $photo->toArray();
     $photoArray['url'] = '/photo/' . $photo->id;
     $photo->makeThumbnail();
     return ['status' => 'done', 'files' => [$photoArray]];
 }
예제 #11
0
 /**
  * Store a newly created resource in storage.
  *
  * @param TrophyRequest $request
  * @return Response
  */
 public function store(TrophyRequest $request)
 {
     $icon = $request->icon ? $request->icon : null;
     $color = $request->color ? $request->color : null;
     if ($request->hasFile('photo') && $request->file('photo')->isValid()) {
         // Create name for new Image
         $photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
         // Move image to storage
         $image = Image::make($request->file('photo'));
         $image->fit(500)->save(public_path('uploaded_images/') . $photoName);
         $photo = Photo::create(['url' => $photoName]);
         $request->user()->createTrophy()->create(['name' => $request->name, 'short_name' => $request->short_name, 'description' => $request->description, 'photo_id' => $photo->id, 'max_bearer' => $request->max_bearer, 'icon' => $icon, 'color' => $color]);
         return back()->with('success', 'Trophy Created Successfully!');
     }
     return back()->with('error', 'Some Error in Form!')->withInput();
 }
 protected function generate($year, $month)
 {
     HttpClient::init(['applicationId' => env('IMG_ID'), 'secret' => env('IMG_SECRET')]);
     $date = Carbon::now();
     $date->year = $year;
     $date->month = $month;
     $date->startOfMonth();
     $end = $date->copy()->endOfMonth();
     while ($date->lte($end)) {
         $random = uPhoto::random();
         $link = $random->links['html'];
         $image = $random->urls['thumb'];
         Photo::create(['date' => $date->toDateString(), 'link' => $link, 'image' => $image]);
         $date->addDays(1);
     }
     return redirect('view/' . $year . '/' . $month);
 }
예제 #13
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $images = Input::file('images');
     $album_id = Input::get('album_id');
     foreach ($images as $image) {
         //$names[] = $image->getClientOriginalName();
         $destinationPath = 'public/images';
         // upload path
         $fileName = $image->getClientOriginalName();
         $image->move($destinationPath, $fileName);
         // uploading file to given path
         $image = Photo::create(['name' => $image->getClientOriginalName(), 'album_id' => $album_id]);
     }
     //dd($input);
     //dd($input);
     //$id = Input::get('album_id');
     //$photo = Photo::create($input);
     //$article->tags()->attach(Input::get('tag_list'));
     return redirect('/');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(PhotoRequest $request)
 {
     // Create new photo
     $photo = Photo::create(['title' => $request->get('title')]);
     // Set image name as suglify title in lower case
     $imageName = $photo->id . '.' . Str::slug($photo->title) . '.' . $request->file('image')->getClientOriginalExtension();
     $imageName = Str::lower($imageName);
     // Move file to storage location
     $imagePath = storage_path() . '/uploads/img/';
     $request->file('image')->move($imagePath, $imageName);
     // Add image filename to model
     $photo->update(['filename' => $imageName]);
     // Fire event to resize photos
     event(new PhotoSaved($photo));
     /*
      * Redirect to photos route with session
      * of the updated entry
      */
     return redirect()->route('dash.photos')->with(['flash_entry_updated' => true, 'flash_entry_id' => $photo->id, 'flash_entry_title' => $photo->title, 'flash_entry_route' => 'dash.photos.edit']);
 }
예제 #15
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array $data
  * @return User
  */
 protected function create(array $data)
 {
     if (isset($data['photo']) && $data['photo']->isValid()) {
         $photoName = md5(Carbon::now()) . "." . $data['photo']->getClientOriginalExtension();
         $image = Image::make($data['photo']);
         $image->fit(300)->save(public_path('images/') . $photoName);
         $photo = Photo::create(['url' => $photoName]);
         $photoId = $photo->id;
     } else {
         $photoId = null;
     }
     /**
      * Allow Insertion of Batch only if Submitter is Student
      */
     $batch = $data['type'] == 0 ? $data['batch'] : null;
     $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'username' => $data['username'], 'password' => bcrypt($data['password']), 'gender' => $data['gender'], 'type' => $data['type'], 'college_id' => $data['college_id'], 'department_id' => $data['department_id'], 'photo_id' => $photoId, 'batch' => $batch, 'register_time_ip' => \Request::getClientIp()]);
     /**
      * EMAIL User a Welcome Email
      * @TODO: Add this to a Queue and extract to a Event Listener
      */
     /*$this->mailer->welcome($user);*/
     /**
      * Create Alumini
      */
     if (isset($data['alumini'])) {
         $slug = slug_for_url($data['name'] . ' of ' . $data['batch'] . '-' . $data['profession']);
         $speech = empty($data['speech']) ? null : $data['speech'];
         $facebook = empty($data['facebook']) ? null : $data['facebook'];
         $organisation_id = empty($data['organisation_id']) ? null : $data['organisation_id'];
         $user->aluminis()->create(['speech' => $speech, 'speaker' => $data['name'], 'batch' => $batch, 'department_id' => $data['department_id'], 'profession' => $data['profession'], 'organisation_id' => $organisation_id, 'photo_id' => $photoId, 'email' => $data['email'], 'facebook' => $facebook, 'slug' => $slug]);
     }
     \Session::flash('user.has.registered', true);
     /**
      *Subscribe this user to Weekly Newsletter
      * @TODO: Enable this in production
      */
     //Newsletter::subscribe($user->email);
     return $user;
 }
예제 #16
0
 public function update(Request $request, AppMailer $mailer)
 {
     $user = Auth::user();
     // Validate request
     $this->validate($request, ['email' => 'required|unique:users,email,' . $user->id, 'tel_no' => 'required_if:type,1|unique:users,tel_no,' . $user->id]);
     $message = 'Your account has been updated!';
     // Email update
     if ($user->email != $request->email) {
         $user->email = $request->email;
         $user->verified = false;
         $user->generateConfirmationLink();
         $mailer->sendEmailConfirmation($user, true);
         $message = $message . ' Please confirm your email.';
     }
     // Phone update
     $user->tel_no = $request->tel_no;
     // Description update
     $user->description = $request->description;
     if ($request->file('image')) {
         //IMAGE STUFF
         //make timestamp and append username for filename
         $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
         $imageFile = Input::file('image');
         $mime = "." . substr($imageFile->getMimeType(), 6);
         //move file to /public/images/
         $filename = $timestamp . '-' . $user->username;
         $photoData = array('fileName' => $filename, 'mime' => $mime);
         $photo = Photo::create($photoData);
         $imageFile->move(public_path() . '/images/uploads/', $filename . $mime);
         //associate the image with the user
         $user->photo_id = $photo->id;
         $user->photo()->associate($photo);
     }
     $user->save();
     session()->flash('message', $message);
     return Redirect::route('dashboard');
 }
예제 #17
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //authenticate and get user id
     $user = JWTAuth::parseToken()->authenticate();
     $user_id = $user->id;
     $validator = Validator::make($request->all(), array('photo' => 'mimes:jpg,jpeg,png'));
     if ($validator->fails()) {
         return $validator->errors()->all();
     } else {
         if ($user->photo_count < 5) {
             $photo = $request->file('photo');
             $random_string = md5(microtime());
             $name = 'photos/' . $user->id . '-' . $random_string . '.' . $request->file('photo')->getClientOriginalExtension();
             Storage::put($name, file_get_contents($request->file('photo')->getRealPath()));
             //Storage::disk('local')->put($name,File::get($photo));
             $photo = Photo::create(['photo_location' => $name, 'user_id' => $user_id]);
             $user->photo_count = $user->photo_count + 1;
             $user->save();
             return response()->json(['success' => true, 'message' => "Successfully uploaded"]);
         } else {
             return response()->json(['success' => false, 'message' => "More than 5 photos are not allowed"]);
         }
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request)
 {
     if ($request->file('character_avatar') != null) {
         $sInputImageName = str_replace(' ', '_', Input::get('character_name') . '_' . $request->file('character_avatar')->getClientOriginalName());
         $sImageName = rand(1, 1000000) . '_' . Session::get('user')['id'] . '_' . $sInputImageName;
         $request->file('character_avatar')->move(base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_CHARACTER_NORMAL, $sImageName);
         $filename = base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_CHARACTER_NORMAL . $sImageName;
         $jpeg_quality = 90;
         $targ_w = $targ_h = 150;
         switch ($request->file('character_avatar')->getClientOriginalExtension()) {
             case 'jpeg':
             case 'jpg':
                 $source = imagecreatefromjpeg($filename);
                 $img_r = imagecreatefromjpeg($filename);
                 $dst_r = imagecreatetruecolor($targ_w, $targ_h);
                 imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), $targ_w, $targ_h, Input::get('w'), Input::get('h'));
                 //imagejpeg($dst_r, base_path().'/public/avatars/characters/mini/'. $sImageName, $jpeg_quality);
                 header('Content-type: image/jpeg');
                 imagejpeg($dst_r, base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_CHARACTER_MINI . $sImageName, $jpeg_quality);
                 break;
             case 'png':
                 $source = imagecreatefrompng($filename);
                 $img_r = imagecreatefrompng($filename);
                 $dst_r = imagecreatetruecolor($targ_w, $targ_h);
                 imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), $targ_w, $targ_h, Input::get('w'), Input::get('h'));
                 //imagejpeg($dst_r, base_path().'/public/avatars/characters/mini/'. $sImageName, $jpeg_quality);
                 header('Content-type: image/jpeg');
                 imagepng($dst_r, base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_CHARACTER_MINI . $sImageName, 9);
                 break;
             case 'gif':
                 $source = imagecreatefromgif($filename);
                 $img_r = imagecreatefromgif($filename);
                 $dst_r = imagecreatetruecolor($targ_w, $targ_h);
                 imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), $targ_w, $targ_h, Input::get('w'), Input::get('h'));
                 //imagejpeg($dst_r, base_path().'/public/avatars/characters/mini/'. $sImageName, $jpeg_quality);
                 header('Content-type: image/jpeg');
                 imagegif($dst_r, base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_CHARACTER_MINI . $sImageName, $jpeg_quality);
                 break;
             default:
                 $source = imagecreatefromjpeg($filename);
                 break;
         }
         $oCharacter = Character::where('id', Input::get('character_id'))->first()->toArray();
         $aPhoto = Photo::create(['user_id' => Session::get('user')['id'], 'photo_type' => Photo::PHOTO_TYPE_CHARACTER, 'photo_link' => Photo::PHOTO_LINK_AVATAR_CHARACTER_MINI . $sImageName, 'status' => Photo::PHOTO_STATUS_DEFAULT]);
         if ($request->all()) {
             Character::where('id', Input::get('character_id'))->update(['character_name' => Input::get('character_name') != "" ? Input::get('character_name') : $oCharacter['character_name'], 'character_age' => Input::get('character_age') != "" ? Input::get('character_age') : $oCharacter['character_age'], 'character_avatar' => Photo::PHOTO_LINK_AVATAR_CHARACTER_NORMAL . $sImageName, 'character_avatar_mini' => Photo::PHOTO_LINK_AVATAR_CHARACTER_MINI . $sImageName, 'character_description' => Input::get('character_description') != "" ? Input::get('character_description') : $oCharacter['character_description'], 'photo_id' => $aPhoto['id']]);
             return json_encode(Character::where('id', Input::get('character_id'))->first()->toArray());
         }
     }
     $oCharacter = Character::where('id', Input::get('character_id'))->first()->toArray();
     if ($request->all()) {
         Character::where('id', Input::get('character_id'))->update(['character_name' => Input::get('character_name') != "" ? Input::get('character_name') : $oCharacter['character_name'], 'character_age' => Input::get('character_age') != "" ? Input::get('character_age') : $oCharacter['character_age'], 'character_description' => Input::get('character_description') != "" ? Input::get('character_description') : $oCharacter['character_description']]);
         return json_encode(Character::where('id', Input::get('character_id'))->first()->toArray());
     }
 }
 public function addPhoto(Request $request, $id)
 {
     $result = $request->all();
     $result['placeId'] = $id;
     $rules = array('file' => 'image|max:3000');
     $validation = Validator::make($result, $rules);
     if ($validation->fails()) {
         return \Response::make($validation->errors->first(), 400);
     }
     $destinationPath = 'uploads';
     // upload path
     $extension = Input::file('file')->getClientOriginalExtension();
     // getting file extension
     $fileName = rand(11111, 99999) . '.' . $extension;
     // renameing image
     $upload_success = Input::file('file')->move($destinationPath, $fileName);
     // uploading file to given path
     $result['photoUrl'] = $destinationPath . '\\' . $fileName;
     if ($upload_success) {
         Photo::create($result);
         return \Response::json('success', 200);
     } else {
         return \Response::json('error', 400);
     }
 }
예제 #20
0
파일: Post.php 프로젝트: bbig979/shoppyst
 public static function storeCMPicture($img_url)
 {
     // post save
     $post = \App\Post::create(array('user_id' => \Auth::user()->id, 'content' => ''));
     $post->postGroups()->attach(\Auth::user()->postGroups()->first()->id);
     // photo save
     $types = array('_s.', '_m.', '_l.');
     $sizes = array(100, 300, 600);
     $original_file_name = $img_url;
     $file_ext = 'jpg';
     $target_path = base_path() . '/public/imgs/';
     $hashSeed = "post" . $post->id . $original_file_name;
     while (1) {
         $file_name = \Func::getHashedValue($hashSeed);
         if (!\File::exists($target_path . \Func::getImgPath($file_name))) {
             break;
         }
         $hashSeed .= rand();
     }
     $target_path .= \Func::getImgPath($file_name) . '/';
     if (!\File::exists($target_path)) {
         \File::makeDirectory($target_path, 0775, true);
     }
     foreach ($types as $key => $type) {
         $new_name = $file_name . $type . $file_ext;
         $img = \Image::make($img_url);
         $img->resize($sizes[$key], null, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->save($target_path . $new_name);
         $img->destroy();
     }
     \App\Photo::create(array('post_id' => $post->id, 'sequence' => 1, 'img_path' => $file_name . '.' . $file_ext));
 }
 /**
  * Save photos uploaded with the form into
  * the Photo model.
  *
  * @param object $request
  * @param object $work
  *
  * @return void
  */
 public function savePhotos($request, $work)
 {
     // Bail early if we don't have any files
     if (!$request->hasFile('photos')) {
         return;
     }
     $files = $request->file('photos');
     // Loop through all files and create new entries
     foreach ($files as $key => $file) {
         $photoTitle = Str::substr($work->title, 0, 10);
         // Create new photo
         $photo = Photo::create(['title' => $photoTitle]);
         // Set image name as slugify title in lowercase
         $imageName = $photo->id . '.' . Str::slug($photoTitle) . '.' . $file->getClientOriginalExtension();
         $imageName = Str::lower($imageName);
         // Move file to storage location
         $imagePath = storage_path() . '/uploads/img/';
         $file->move($imagePath, $imageName);
         // Add image filename to model
         $photo->update(['filename' => $imageName, 'work_id' => $work->id]);
     }
 }
예제 #22
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param Alumini $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, Alumini $id)
 {
     if ($request->user()->can('edit', $id)) {
         $this->validate($request, ['speaker' => 'required|min:5', 'speech' => '', 'profession' => 'required', 'batch' => 'required|min:2', 'organisation_id' => 'exists:organisations,id', 'email' => 'required|email', 'facebook' => '', 'department_id' => 'required|exists:departments,id', 'user_id' => 'required|exists:users,id', 'photo' => 'image|max:500']);
         /**
          * If Request has Photo Uploaded Then
          * 1> Delete prev Image
          * 2> Store Photo in storage and link in DB
          * 3> Pass new PhotoId
          */
         if ($request->hasFile('photo') && $request->file('photo')->isValid()) {
             // Create name for new Image
             $photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
             // Move image to storage
             $request->file('photo')->move(public_path('images'), $photoName);
             $photo = Photo::create(['url' => $photoName]);
             /*
              * Delete previous pic if any
              * Delete only if this Photo is not referenced by any User profile.
              */
             if ($prevPic = $id->photo) {
                 // If any User references then ignore deletion else delete
                 if (User::where('photo_id', $prevPic->id)->first() == null) {
                     $file = public_path('images/') . $prevPic->url;
                     if (File::exists($file)) {
                         // Delete from Storage
                         File::delete($file);
                         // Delete link from DB
                         $id->photo_id = null;
                         $id->save();
                         $prevPic->delete();
                     }
                 }
             }
             $photoId = $photo->id;
         } else {
             if ($prevPic = $id->photo) {
                 $photoId = $prevPic->id;
             } else {
                 $photoId = null;
             }
         }
         $speech = empty($request->speech) ? null : $request->speech;
         $facebook = empty($request->facebook) ? null : $request->facebook;
         $organisation_id = empty($request->organisation_id) ? null : $request->organisation_id;
         $id->update(['speaker' => $request->speaker, 'speech' => $speech, 'profession' => $request->profession, 'batch' => $request->batch, 'organisation_id' => $organisation_id, 'email' => $request->email, 'facebook' => $facebook, 'department_id' => $request->department_id, 'user_id' => $request->user_id, 'photo_id' => $photoId]);
         if ($request->user()->isAdmin() || $request->user_id == $request->user()->id) {
             return back()->withNotification('Alumini has been updated')->withType('success');
         } else {
             return redirect()->route('alumini.index')->withNotification("Alumini has been updated");
         }
     } else {
         return redirect('/')->withNotification('You are not authorized')->withType('danger');
     }
 }
예제 #23
0
 public function create(CreatePhotoRequest $request)
 {
     Photo::create($request->all());
     $request->file('photo')->move('photos/' . $request->album_name . '/', $request->photo_name . '.jpg');
     return redirect('pixelbug/loggedin/add');
 }
예제 #24
0
 public function syncPhotos(Tour $tour, array $photoIds)
 {
     $tour_id = $tour->id;
     $tour->photos()->delete();
     foreach ($photoIds as $photo_id) {
         Photo::create(compact('tour_id', 'photo_id'));
     }
 }
 public function update_profile_avatar(Request $request)
 {
     if ($request->file('user_avatar') != null) {
         $sInputImageName = str_replace(' ', '_', Session::get('user')['user_name'] . '_' . $request->file('user_avatar')->getClientOriginalName());
         $sImageName = rand(1, 1000000) . '_' . Session::get('user')['id'] . '_' . $sInputImageName;
         $request->file('user_avatar')->move(base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_USER, $sImageName);
         $filename = base_path() . '/public/' . Photo::PHOTO_LINK_AVATAR_USER . $sImageName;
         $aPhoto = Photo::create(['user_id' => Session::get('user')['id'], 'photo_type' => Photo::PHOTO_TYPE_USER, 'photo_link' => Photo::PHOTO_LINK_AVATAR_USER . $sImageName, 'status' => Photo::PHOTO_STATUS_DEFAULT]);
         $result = User::where('id', Session::get('user')['id'])->update(['avatar' => Photo::PHOTO_LINK_AVATAR_USER . $sImageName, 'photo_id' => $aPhoto['id']]);
         if ($result) {
             return response()->json(['link' => (string) Photo::PHOTO_LINK_AVATAR_USER . $sImageName, 'status' => true, 'message' => "Successfully archived character"]);
         } else {
             return response()->json(['status' => false, 'message' => "Something went wrong. Please try again"]);
         }
     }
 }
예제 #26
0
 public function addTestPhotosToDatabase()
 {
     Photo::create(array('slug' => 'img1', 'image_name' => 'img-0.jpg', 'thumbnail_name' => 'img-0.jpg', 'date_of_photo' => '2015-08-02', 'description' => 'Seventh photo'));
     Photo::create(array('slug' => 'img1', 'image_name' => 'img-0.jpg', 'thumbnail_name' => 'img-0.jpg', 'date_of_photo' => '2015-08-02', 'description' => 'Seventh photo'));
     Photo::create(array('slug' => 'img1', 'image_name' => 'img-0.jpg', 'thumbnail_name' => 'img-0.jpg', 'date_of_photo' => '2015-08-03', 'description' => 'Eighth  photo'));
     Photo::create(array('slug' => 'img1', 'image_name' => 'img-0.jpg', 'thumbnail_name' => 'img-0.jpg', 'date_of_photo' => '2015-08-03', 'description' => 'Eighth  photo'));
     Photo::create(array('slug' => 'img1', 'image_name' => 'img-0.jpg', 'thumbnail_name' => 'img-0.jpg', 'date_of_photo' => '2015-08-04', 'description' => 'Ninth   photo'));
     Photo::create(array('slug' => 'img1', 'image_name' => 'img-0.jpg', 'thumbnail_name' => 'img-0.jpg', 'date_of_photo' => '2015-08-04', 'description' => 'Ninth   photo'));
     return "Photos Added";
 }
예제 #27
0
 public function updateProfile2(Request $request)
 {
     $user = $request->user();
     $this->validate($request, ['dob' => 'date|before:2016-01-01', 'name' => 'required', 'about' => 'min:5', 'gender' => 'in:Male,Female,unspecified,Others', 'gr_id' => 'numeric', 'facebook_url' => 'url', 'website_url' => 'url', 'photo' => 'image|max:500'], ['dob.required' => 'Please specify your Date of Birth.', 'dob.date' => 'Invalid Date of Birth format', 'dob.before' => 'You are not enough old :)', 'name.required' => 'Please specify your Display name', 'gr_id.numeric' => 'Please enter a valid GameRanger account Id', 'faccebook_url.url' => 'Facebook URL is not valid. Please prefix "http://"', 'website_url.url' => 'Website URL is not valid. Please prefix "http://"', 'photo.image' => "Profile picture must be image type", 'photo.max' => "Profile picture must not be greater than 500kb in size"]);
     $dob = $request->dob ? $request->dob : null;
     $grid = $request->gr_id ? $request->gr_id : null;
     $fburl = $request->facebook_url ? $request->facebook_url : null;
     $weburl = $request->website_url ? $request->website_url : null;
     $evolveid = $request->evolve_id ? $request->evolve_id : null;
     $steam_nickname = $request->steam_nickname ? $request->steam_nickname : null;
     $discord_username = $request->discord_username ? $request->discord_username : null;
     $about = $request->about ? $request->about : null;
     $gender = $request->gender ? $request->gender : null;
     $gender = $gender == 'unspecified' ? null : $gender;
     if ($request->has('email_notifications_new_message')) {
         $email_notifications_new_message = true;
     } else {
         $email_notifications_new_message = false;
     }
     // Background image only available for Elders++
     if ($request->user()->isSubAdmin()) {
         $back_img_url = $request->back_img_url ? $request->back_img_url : null;
     } else {
         $back_img_url = $request->user()->back_img_url;
     }
     /**
      * If Request has Photo Uploaded Then
      * 1> Delete prev Image
      * 2> Store Photo in storage and link in DB
      * 3> Pass new PhotoId
      */
     if ($request->hasFile('photo') && $request->file('photo')->isValid()) {
         // Create name for new Image
         $photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
         // Move image to storage
         $image = Image::make($request->file('photo'));
         $image->fit(300)->save(public_path('uploaded_images/') . $photoName);
         $photo = Photo::create(['url' => $photoName]);
         /*
          * Delete previous Profile pic if any
          * Delete only if this Photo is not referenced by any Alumini profile.
          */
         if ($prevPic = $request->user()->photo) {
             // If any alumini references then ignore deletion else delete
             $file = public_path('uploaded_images/') . $prevPic->url;
             if (File::exists($file)) {
                 // Delete from Storage
                 File::delete($file);
                 // Delete link from DB
                 $user->photo_id = null;
                 $user->save();
                 $prevPic->delete();
             }
         }
         $photoId = $photo->id;
     } else {
         if ($prevPic = $request->user()->photo) {
             $photoId = $prevPic->id;
         } else {
             $photoId = null;
         }
     }
     $user->update(['dob' => $dob, 'name' => $request->name, 'about' => $about, 'gender' => $gender, 'gr_id' => $grid, 'evolve_id' => $evolveid, 'facebook_url' => $fburl, 'website_url' => $weburl, 'photo_id' => $photoId, 'steam_nickname' => $steam_nickname, 'discord_username' => $discord_username, 'email_notifications_new_message' => $email_notifications_new_message, 'back_img_url' => $back_img_url]);
     return \Redirect::back()->with('message', "Profile has been updated!");
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param KTournamentRequest $request
  * @return Response
  */
 public function store(KTournamentRequest $request)
 {
     if (!$request->user()->isSuperAdmin()) {
         return redirect()->home();
     }
     if ($request->hasFile('photo')) {
         if ($request->file('photo')->isValid()) {
             $photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
             $request->file('photo')->move(public_path('uploaded_images'), $photoName);
             $photo = Photo::create(['url' => $photoName]);
             $slug = str_slug($request->name);
             $tournament = $request->user()->createdtournaments()->create(['name' => $request->name, 'description' => $request->description, 'rules' => $request->rules, 'minimum_participants' => $request->minimum_participants, 'maximum_participants' => $request->maximum_participants, 'rounds_per_match' => $request->rounds_per_match, 'registration_starts_at' => $request->registration_starts_at, 'registration_ends_at' => $request->registration_ends_at, 'tournament_starts_at' => $request->tournament_starts_at, 'photo_id' => $photo->id, 'slug' => $slug, 'bracket_type' => $request->bracket_type, 'tournament_type' => $request->tournament_type]);
             if ($request->managers) {
                 $tournament->managers()->sync($request->managers);
             }
             // Create notification
             $not = new Notification();
             $not->from($request->user())->withType('TournamentCreated')->withSubject('A tournament created.')->withBody("A new tournament has been created : " . link_to_route('tournament.show', $tournament->name, $tournament->slug))->withStream(true)->regarding($tournament)->deliver();
             return redirect()->route('tournament.show', $slug)->with('success', 'Tournament has been created!');
         }
     } else {
         return back()->with('error', 'Error! Try Again.');
     }
 }
예제 #29
0
 /**
  * Update the event's details
  * 
  * @param  EventEditRequest $request The User's Request
  * @param  [type]           $id      id of the event
  */
 public function update(EventEditRequest $request, $id)
 {
     $event = Event::find($id);
     // Parse date and time into a carbon instance
     $dateTime = $request['event_date'] . " " . $request['event_time'];
     $carbon = Carbon::createFromFormat('d F, Y H:i', $dateTime);
     $request['event_time'] = $carbon;
     // remove all old tags before attaching new ones
     $event->tags()->detach($event->tags()->lists('id')->toArray());
     // trim custom tags for whitespace and make array
     $trimmedTags = preg_replace('/\\s+/', '', $request['customTags']);
     $tags = explode(',', $trimmedTags);
     if ($tags) {
         foreach ($tags as $tag) {
             $event->tags()->attach(Tag::firstOrCreate(array('name' => $tag)));
         }
     }
     if ($request['tags']) {
         foreach ($request['tags'] as $tag) {
             $event->tags()->attach(Tag::find($tag));
         }
     }
     if ($request->file('image')) {
         $imageFile = $request->file('image');
         //make timestamp and append event name for filename
         $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
         $filename = $timestamp . '-' . $event->name;
         //remove 'image/' from MIME type
         $mime = "." . substr($imageFile->getMimeType(), 6);
         //move file to /public/images/
         $filename = $timestamp . '-' . $event->name;
         $photoData = array('fileName' => $filename, 'mime' => $mime);
         $photo = Photo::create($photoData);
         //move uploaded file to public dir
         $imageFile->move(public_path() . '/images/uploads/', $filename . $mime);
         $event->photo()->dissociate($event->photo_id);
         //associate the image with the user
         $event->photo_id = $photo->id;
         $event->photo()->associate($photo);
         $event->save();
     }
     $attributes = $request->only('name', 'event_time', 'event_type', 'gmaps_id', 'description');
     // Update the fields shown in the form
     Event::find($id)->update($attributes);
     // Show updated event
     $event = Event::find($id);
     return view('events.show', compact('event'));
 }
 function create(Request $request)
 {
     if (Session::has('user')) {
         //Check the type of comment type to determine what id is to be inserted [photo_id, character_id, family_id, specy_id, post_id, mate_id]
         $iFromType = Input::get('comment-from-type');
         $iFromWhereID = null;
         $iCommentPhotoID = 0;
         $aComment = [];
         switch ($iFromType) {
             case Comment::COMMENT_FROM_TYPE_USER:
                 $iFromWhereID = "user_id";
                 break;
             case Comment::COMMENT_FROM_TYPE_CHARACTER:
                 $iFromWhereID = "character_id";
                 break;
             case Comment::COMMENT_FROM_TYPE_FAMILY:
                 $iFromWhereID = "family_id";
                 break;
             case Comment::COMMENT_FROM_TYPE_SPECY:
                 $iFromWhereID = "specy_id";
                 break;
             case Comment::COMMENT_FROM_TYPE_PHOTO:
                 $iFromWhereID = "photo_id";
                 break;
             case Comment::COMMENT_FROM_TYPE_POST:
                 $iFromWhereID = "post_id";
                 break;
             case Comment::COMMENT_FROM_TYPE_MATE:
                 $iFromWhereID = "mate_id";
                 break;
         }
         $oComment = Comment::create(['from_user_id' => Session::get('user')['id'], 'to_user_id' => Input::get('comment-to-user-id'), 'comment_text' => Input::get('comment-text'), 'status' => Comment::COMMENT_STATUS_DEFAULT, 'comment_type' => $request->file('comment-photo') != null ? Comment::COMMENT_TYPE_PHOTO : Comment::COMMENT_TYPE_TEXT, 'comment_from_type' => Input::get('comment-from-type'), $iFromWhereID => Input::get('comment-from-id'), 'comment_photo_id' => $iCommentPhotoID]);
         //Check if there's a file
         if ($request->file('comment-photo') != null) {
             $sInputImageName = str_replace(' ', '_', Input::get('comment-to-user-id') . '_' . $request->file('comment-photo')->getClientOriginalName());
             $sImageName = rand(1, 1000000) . '_' . Session::get('user')['id'] . '_' . $sInputImageName;
             $request->file('comment-photo')->move(base_path() . '/public/' . Photo::PHOTO_LINK_COMMENT, $sImageName);
             $oPhoto = Photo::create(['user_id' => Session::get('user')['id'], 'photo_type' => Photo::PHOTO_TYPE_COMMENT, 'photo_link' => Photo::PHOTO_LINK_COMMENT . $sImageName, 'status' => Photo::PHOTO_STATUS_DEFAULT]);
             $iCommentPhotoID = $oPhoto->toArray()['id'];
             if ($oPhoto) {
                 Comment::where('id', $oComment->toArray()['id'])->update(['comment_photo_id' => $iCommentPhotoID]);
             }
         }
         if ($oComment) {
             $aComment = Comment::where('id', $oComment->toArray()['id'])->first()->toArray();
             $aNotification = Notification::create(['from_user_id' => Session::get('user')['id'], 'to_user_id' => Input::get('comment-to-user-id'), 'notification_type' => Notification::NOTIFICATION_TYPE_COMMENT, 'status' => Notification::NOTIFICATION_STATUS_ACTIVE, 'comment_id' => $aComment['id']]);
             Update::create(['user_id' => Session::get('user')['id'], 'update_type' => Update::UPDATE_TYPE_COMMENT, 'comment_id' => $aComment['id'], 'status' => Update::UPDATE_STATUS_ACTIVE]);
             //FOR DISPLAY
             $aComment['from_user'] = User::where('id', Session::get('user')['id'])->first()->toArray();
             $aComment['photo_comment'] = $aComment['comment_photo_id'] > 0 ? Photo::where('id', $aComment['comment_photo_id'])->first()->toArray() : [];
         }
         $view = view('users.comments.partials.partial-comment-owner')->with('aComment', $aComment);
         if ($aComment) {
             return response()->json(['status' => true, 'message' => "Successfully submitted comment", 'view' => (string) $view]);
         } else {
             return response()->json(['status' => false, 'message' => "Something went wrong. Please try again"]);
         }
     }
 }