/** * Execute the job. * * @return void */ public function handle() { if ($this->newOnly) { $photosQueryBuilder = Photo::where('posted_date', '=', '0000-00-00'); } else { $photosQueryBuilder = Photo::where('id', '>', 0); } $photos = $photosQueryBuilder->get(); $gridColumns = [(new FieldConfig('id'))->setLabel('Actions')->setSortable(true)->setCallback(function ($val, EloquentDataRow $row) { $rowData = $row->getSrc(); $iconShow = '<span class="fa fa-eye"></span> '; $hrefShow = action('PhotosController@show', [$val]); $iconUpdate = '<span class="fa fa-pencil"></span> '; $hrefUpdate = action('PhotosController@edit', [$val]); $iconDelete = '<span class="fa fa-times"></span> '; $hrefDelete = action('PhotosController@delete', [$val]); $iconTumblr = '<span class="fa fa-tumblr-square"></span> '; $hrefTumblr = $rowData->url; return '<a href="' . $hrefShow . '">' . $iconShow . '</a> ' . '<a href="' . $hrefUpdate . '">' . $iconUpdate . '</a> ' . '<a href="' . $hrefDelete . '">' . $iconDelete . '</a> ' . '<a href="' . $hrefTumblr . '" target="_blank">' . $iconTumblr . '</a>'; }), (new FieldConfig('file_name'))->setLabel('Photo')->setCallback(function ($val, EloquentDataRow $row) { $rowData = $row->getSrc(); $image = '<img src="/photo_files/thumbnail/' . $val . '" />'; $hrefShow = action('PhotosController@show', [$rowData->id]); return '<a href="' . $hrefShow . '">' . $image . '</a>'; }), (new FieldConfig('posted_date'))->setSortable(true)->setSorting(Grid::SORT_DESC), (new FieldConfig('notes'))->setSortable(true), (new FieldConfig('notes_last30'))->setSortable(true)->setLabel('Last 30 Days'), (new FieldConfig('notes_last10'))->setSortable(true)->setLabel('Last 10 Days')]; $gridCfg = (new GridConfig())->setDataProvider(new EloquentDataProvider($photosQueryBuilder))->setColumns($gridColumns); $grid = new Grid($gridCfg); return array('narrowGrid' => null, 'grid' => $grid); }
/** * Checks to see whether the slug passed is unique * * @param $slug * @return bool */ public static function isSlugUnique($slug) { if (!Photo::where('slug', '=', $slug)->first()) { return true; } else { return false; } }
/** * Handle the event. * * @param UserWasDeleted $event * @return void */ public function handle(UserWasDeleted $event) { // Delete everything the user created Article::where('user_id', $event->user_id)->delete(); Photo::where('user_id', $event->user_id)->delete(); PhotoAlbum::where('user_id', $event->user_id)->delete(); Video::where('user_id', $event->user_id)->delete(); VideoAlbum::where('user_id', $event->user_id)->delete(); }
public function viewReadOnePublic($id) { // Set logged in user to a variable. $authUser = Auth::user(); // Find the user in the database. $user = User::findOrFail($id); $photos = Photo::where('user_id', '=', $user->id)->where('private', '=', 0)->latest('id')->paginate(12); // Return view with variables. return view('user.viewReadOnePublic')->with('authUser', $authUser)->with('user', $user)->with('photos', $photos); }
public function multiple_upload(Request $request) { /* * Tests incoming files to make sure there's no duplicates in db */ // getting all of the post data $files = Input::file('userfile'); // Making counting of uploaded images $file_count = count($files); // start count how many uploaded $uploadcount = 0; $hash_type = 'md5'; // don't change this on an existing database! $filepath = 'img/'; $thumbpath = 'img/thumbs/'; foreach ($files as $file) { if (in_array(exif_imagetype($file), array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { $filename = $file->getClientOriginalName(); $extension = strtolower($file->getClientOriginalExtension()); $photo = new Photo(); //photo db object $photo->filename = $filename; $photo->extension = $extension; $photo->save(); $currImg = Image::make($file); $currFilePath = $filepath . $photo->id . "." . $extension; $currImg->orientate()->save($currFilePath); // saving the actual file $hashcheck = hash_file($hash_type, $currFilePath); $hasDuplicate = Photo::where('hash', $hashcheck)->first(); if ($hasDuplicate) { // rollback if duplicate found File::delete($currFilePath); $photo->delete(); } else { $currImg->heighten(174)->save($thumbpath . $photo->id . "_thumb" . "." . $extension); $photo->hash = hash_file($hash_type, $currFilePath); // hash generated after we save the file $photo->notes = $request->input('note'); $photo->image_subject = "Rosemary"; $photo->save(); $uploadcount++; } $currImg->destroy(); // free up memory } } return $file_count - $uploadcount; }
public function delete(PhotoDeleteRequest $request) { if (!$request->has('filename')) { return; } $photo = Photo::where('disk_name', $request->get('filename'))->first(); if (Auth::user()->hasRole('admin')) { $this->deleteFile($photo); } else { if ($photo->user_id == Auth::user()->id) { $this->deleteFile($photo); } } return response()->json(['status', 'ok']); }
public function postChangePhoto(Request $request, \App\User $user) { if ($request->file('user_photo')->isValid()) { $destinationPath = base_path() . '/public/images/uploads'; $extension = $request->file('user_photo')->getClientOriginalExtension(); $fileName = md5($request->file('user_photo')->getFileName()) . '.' . $extension; $moved = $request->file('user_photo')->move($destinationPath, $fileName); if (!$moved) { return redirect('/')->withMessage('There was a problem uploading your photo.'); } $photo = \App\Photo::where('user_id', $user->id)->first(); $photo->path = $fileName; $photo->save(); } return redirect('/')->withMessage('Your photo has been updated successfully.'); }
public function deleteRelatedPhotos($id, $model) { $model = 'App\\' . $model; $photos = Photo::where('imageable_type', $model)->where('imageable_id', $id); if (count($photos) > 0) { foreach ($photos->get() as $photo) { $photoPath = public_path('images/uploads/' . $photo->path); try { if (File::isFile($photoPath)) { File::delete($photoPath); } } catch (Exception $e) { } } $photos->delete(); } }
/** * delete a file in a model * * @param $file * * @return bool */ public function imageDelete($file) { $photo = Photo::where('location', $file)->get()->first(); Helper::allow('album-destroy', $photo->album); $path = Helper::getImagePath($file); $photo->delete(); $result = Storage::delete($path); return response()->json(['files' => $result]); }
public function show($id) { $photo_album = PhotoAlbum::find($id); $photos = Photo::where('photo_album_id', $id)->get(); return view('photo.view_album', compact('photos', 'photo_album')); }
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"]); } } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index($id) { $data['photos'] = Photo::where('album_id', $id)->get(); return view('admin.photos', $data); }
/** * Find the related photo on the given Model, If there's an existing * photo, we will loop through them and then delete them one by one. * And finally, we will delete it's record from the "photos" table */ public function deleteExistingPhotos($id, $model) { $model = 'App\\' . $model; $oldPhoto = Photo::where('imageable_type', $model)->where('imageable_id', $id); if (count($oldPhoto) > 0) { foreach ($oldPhoto->get() as $photo) { $oldPhotoPath = public_path('images/uploads/' . $photo->path); if (File::isFile($oldPhotoPath)) { File::delete($oldPhotoPath); } } $oldPhoto->delete(); } }
private function get_name($name) { if (Photo::where(['name' => $name])->count()) { $name = mt_rand(0, 100) . $name; self::get_name($name); } return $name; }
<title>Show All Photos for {{$landmark->name}}</title> @stop @section('content') <div class="container"> <h1>Here are all the photos on the site for:</h1> <h2>{{$landmark->name}}</h2> <div class="centered_text"> @if(Auth::check()) <a href='/photos/{{$landmark->id}}/create'>Add a photo</a> @else @endif </div> <?php $photos = \App\Photo::where('landmark_id', '=', $landmark->id)->orderBy('id')->get(); ?> @foreach($photos as $photo) <?php $user_name = DB::table('users')->where('id', '=', $photo->user_id)->value('name'); ?> <div style="text-align: center" class="user_results_container"> <h2>Photo ID#: {{ $photo->id }}</h2> <div class="centered_text">Uploaded by {{$user_name}}</div> <br> <div class="centered_text">"Description: {{$photo->photo_description}}</div> <br> <div class="outer"> <div class="image"> <img style='width:100%' src={{$photo->filepath}}> </div>
public function ShowTerms($id) { $data['photos'] = Photo::where('album_id', $id)->get(); return view('site.photos', $data); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $blog = \App\Photo::where('blog_id', $id)->get(); return view('photos.show')->with('blog', $blog); }
public function get_details() { $iLimit = 10; $iOffset = 0; if (Input::get('iOffset')) { $iOffset = Input::get('iOffset'); } $htmlView = ""; $bLoggedInUser = Session::has('user'); if ($bLoggedInUser) { $aLoggedInUser['user'] = User::where('id', Session::get('user')['id'])->first()->toArray(); $aLoggedInUser['current_character'] = Character::where('id', $aLoggedInUser['user']['current_character_id'])->first()->toArray(); } //$aMate = Mate::query("SELECT * FROM mates WHERE ((from_user_id = 10 OR to_user_id = 10) AND (status = 8 OR status = 9))")->get()->toArray(); $aMates = DB::select(DB::raw("SELECT * FROM mates WHERE ((from_user_id = " . $aLoggedInUser['user']['id'] . " OR to_user_id = " . $aLoggedInUser['user']['id'] . ") AND (status = " . Mate::MATE_STATUS_ACCEPTED_BY_ADMIN . " OR status = " . Mate::MATE_STATUS_ACCEPTED_BY_USER . "))")); $aUserID = []; $sUserIDS = ""; foreach (json_decode(json_encode($aMates), true) as $aMate) { if ($aMate['from_user_id'] != $aLoggedInUser['user']['id']) { $aUserID[] = $aMate['from_user_id']; $sUserIDS = $sUserIDS . $aMate['from_user_id'] . ", "; } else { $aUserID[] = $aMate['to_user_id']; $sUserIDS = $sUserIDS . $aMate['to_user_id'] . ", "; } } $sUserIDS = substr($sUserIDS, 0, -2); /* $aData = DB::select(DB::raw("SELECT characters.*, comments.*, likes.*, mates.*, posts.*, users.* FROM users LEFT JOIN characters on users.id = characters.user_id LEFT JOIN comments on (characters.user_id = comments.from_user_id OR characters.user_id = comments.to_user_id) LEFT JOIN likes on (comments.from_user_id = likes.from_user_id OR comments.from_user_id = likes.to_user_id OR comments.to_user_id = likes.from_user_id OR comments.to_user_id = likes.to_user_id) LEFT JOIN mates on (likes.from_user_id = mates.from_user_id OR likes.from_user_id = mates.to_user_id OR likes.to_user_id = mates.from_user_id OR likes.to_user_id = mates.to_user_id) LEFT JOIN posts on (likes.from_user_id = posts.from_user_id OR likes.from_user_id = posts.to_user_id OR likes.to_user_id = posts.from_user_id OR likes.to_user_id = posts.to_user_id OR likes.from_user_id = posts.user_id OR likes.to_user_id = posts.user_id) WHERE users.id = " . $aLoggedInUser['user']['id'] . " ORDER BY comments.date_updated, likes.date_updated, likes.date_updated, mates.date_updated, posts.date_updated ASC"));*/ $oUpdates = DB::select(DB::raw("SELECT * FROM updates WHERE\n status = " . Update::UPDATE_STATUS_ACTIVE . " OR\n status = " . Update::UPDATE_STATUS_ACTIVATED_BY_USER . " OR\n status = " . Update::UPDATE_STATUS_ACTIVATED_BY_ADMIN . " AND\n user_id IN (" . $sUserIDS . ")\n ORDER BY id DESC\n LIMIT {$iOffset}, {$iLimit}")); $aUpdates = json_decode(json_encode($oUpdates), true); for ($i = 0; $i < count($aUpdates); $i++) { $aUpdates[$i]['user'] = User::where('id', $aUpdates[$i]['user_id'])->first()->toArray(); switch ($aUpdates[$i]['update_type']) { case Update::UPDATE_TYPE_USER: break; case Update::UPDATE_TYPE_SPECY: break; case Update::UPDATE_TYPE_FAMILY: break; case Update::UPDATE_TYPE_CHARACTER: $aUpdates[$i]['character'] = Character::where('id', $aUpdates[$i]['character_id'])->first()->toArray(); break; case Update::UPDATE_TYPE_MATE: break; case Update::UPDATE_TYPE_COMMENT: $aUpdates[$i]['comment'] = Comment::where('id', $aUpdates[$i]['comment_id'])->first()->toArray(); $aUpdates[$i]['comment']['from_user'] = User::where('id', $aUpdates[$i]['comment']['from_user_id'])->first()->toArray(); $aUpdates[$i]['comment']['to_user'] = User::where('id', $aUpdates[$i]['comment']['to_user_id'])->first()->toArray(); switch ($aUpdates[$i]['comment']['comment_from_type']) { case Comment::COMMENT_FROM_TYPE_USER: break; case Comment::COMMENT_FROM_TYPE_CHARACTER: break; case Comment::COMMENT_FROM_TYPE_FAMILY: break; case Comment::COMMENT_FROM_TYPE_SPECY: break; case Comment::COMMENT_FROM_TYPE_PHOTO: $aUpdates[$i]['comment']['photo'] = Photo::where('id', $aUpdates[$i]['comment']['photo_id'])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_POST: break; case Comment::COMMENT_FROM_TYPE_MATE: break; } $htmlView = $htmlView . (string) view('users.pages.partials.comment-show')->with('aUpdate', $aUpdates[$i]); break; case Update::UPDATE_TYPE_PHOTO: break; case Update::UPDATE_TYPE_LIKE: $aUpdates[$i]['like'] = Like::where('id', $aUpdates[$i]['like_id'])->first()->toArray(); break; case Update::UPDATE_TYPE_POST: $aUpdates[$i]['post'] = Post::where('id', $aUpdates[$i]['post_id'])->first()->toArray(); break; } } return response()->json(['status' => true, 'message' => "Successfully submitted comment", 'view' => (string) $htmlView]); }
public function userphoto($album_name, $photo_id) { $photo = Photo::where('album_name', $album_name)->where('photo_id', $photo_id)->first(); return view('pages.userphoto')->with(['photo' => $photo, 'photo_id' => $photo_id, 'album_name' => $album_name]); }
<!doctype html> <html> @extends('layouts.master') @section('title') <title>Show User's Photos of {{$landmark->name}}</title> @stop @section('content') <?php $photos = \App\Photo::where('landmark_id', '=', $landmark->id)->orderBy(DB::raw('RAND()'))->take(1)->get(); foreach ($photos as $photo) { $filepath = $photo['filepath']; } ?> <div class="image"> <img style='width:20%' src={{$filepath}}> </div> <div class="centered_text"> @if(Auth::check()) <a href='/photos'>All your photos</a> | <a href='/landmarks/show/{{$landmark->id}}'>All photos of {{$landmark->name}}</a> | <a href='/photos/{{$landmark->id}}/create'>Add a photo</a> of {{$landmark->name}} @else @endif </div> <?php $photos = \App\photo::where('landmark_id', '=', $landmark->id)->where('user_id', '=', \Auth::id())->get(); ?> @if(empty($photos->first()))
/** * Reorder items * * @param items list * @return items from @param */ public function getReorder(ReorderRequest $request) { $list = $request->list; $items = explode(",", $list); $order = 1; foreach ($items as $value) { if ($value != '') { Photo::where('id', '=', $value)->update(array('position' => $order)); $order++; } } return $list; }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $product = Product::findBySlug($id); $product_id = $product->id; $categories = Category::all(); $photos = Photo::where('product_id', '=', $product_id)->get(); return view('admin.product.edit', compact('product', 'categories', 'photos')); }
private function attachTagsToNewPhoto($photoId, $tags) { $photo = Photo::where('id', $photoId)->get(); foreach ($tags as $tag) { $tag = Tag::where('tag_name', $tag)->first(); PhotoTag::create(array('photo_id' => $photoId, 'tag_id' => $tag->id)); } }
public function actionDelete($id) { // Set logged in user to a variable. $authUser = Auth::user(); // Find photo in database. $photo = Photo::where('user_id', '=', $authUser->id)->findOrFail($id); // Delete photo from database. $photo->delete($photo); // Redirect with flash message. \Session::flash('flash_message', 'You have successfully deleted a photo.'); return redirect('photos'); }
public function delete($album_name, $photo_id) { Photo::where('album_name', $album_name)->where('photo_id', $photo_id)->delete(); return redirect('/pixelbug/loggedin/' . $album_name); }
public function insertQuery(Request $request) { $type = $request->input('type'); $tag = $request->input('tags'); $id = $request->input('id'); $mode = $request->input('mode'); //////////////////////////////////// //mode = 0 edit , mode = 1 insert/// //////////////////////////////////// if ($type == 'events') { $validator = Validator::make($request->all(), ['title' => 'required', 'address' => 'required', 'body' => 'required', 'tags' => 'required|array']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput()->with(array('errorcode' => 'events', 'tags' => $this->returnTags())); } else { if ($mode == 1) { $event = new Event(); $content = new Content(); } else { $event = Event::find($id); $content = $event->content; } $content->title = $request->input('title'); $event->address = $request->input('address'); $content->body = $request->input('body'); $content->type = $type; $content->save(); $start = $request->input('start-day') . "|" . $request->input('start-month') . "|" . $request->input('start-year') . "|" . $request->input('start-hour') . ":" . $request->input('start-minute'); $end = $request->input('end-day') . "|" . $request->input('end-month') . "|" . $request->input('end-year') . "|" . $request->input('end-hour') . ":" . $request->input('end-minute'); $event->start = $start; $event->end = $end; $event->highlight = $request->input('highlight') == NULL ? 0 : 1; $files = $request->file('img'); foreach ($files as $file) { if ($file->isValid()) { $photo = new Photo(); $tempName = $file->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . "." . $extension[1]; $destination = 'upload'; $file->move($destination, $name); $photo->path = $destination . "/" . $name; $content->photos()->save($photo); } } if (!empty($tag)) { foreach ($tag as $insertTag) { $row = Tag::where('title', '=', $insertTag)->first(); $content->tags()->save($row); } } $cat = Category::where('title', '=', $request->input('category'))->first(); if ($cat != null) { $content->categories()->attach($cat->id); } $content->event()->save($event); return redirect('admin'); } } elseif ($type == 'members') { $validator = Validator::make($request->all(), ['firstname' => 'required', 'lastname' => 'required', 'email' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput()->with(array('errorcode' => 'members', 'tags' => $this->returnTags())); } else { if ($mode == 1) { $member = new Member(); } else { $member = Member::find($id); } $member->firstname = $request->input('firstname'); $member->lastname = $request->input('lastname'); $member->email = $request->input('email'); //$member->password = $request->input('password'); $member->researchareas = $request->input('researchareas') == NULL ? NULL : $request->input('researchareas'); $member->industrialareas = $request->input('intery') == NULL ? NULL : $request->input('industry'); $member->tel = $request->input('telephone') == NULL ? NULL : $request->input('telephone'); $member->mobile = $request->input('mobile') == NULL ? NULL : $request->input('mobile'); $member->position = $request->input('position') == NULL ? NULL : $request->input('position'); $member->googleplus = $request->input('googleplus') == NULL ? NULL : $request->input('pinterest'); $member->facebook = $request->input('facebook') == NULL ? NULL : $request->input('facebook'); $member->twitter = $request->input('twitter') == NULL ? NULL : $request->input('instagram'); $member->linkedin = $request->input('linkedin') == NULL ? NULL : $request->input('linkedin'); if ($request->hasFile('img')) { $file = $request->file('img'); if ($file->isValid()) { $photo = new Photo(); $tempName = $file->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . "." . $extension[1]; $destination = 'upload'; $file->move($destination, $name); //$photo->title = $request->input('photoTitle'); $photo->path = $destination . "/" . $name; Photo::where("member_id", $member->id)->delete(); $member->photo()->save($photo); } } if ($request->hasFile('cv')) { $file = $request->file('cv'); if ($file->isValid()) { $tempName = $file->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . "." . $extension[count($extension) - 1]; $destination = 'upload'; $file->move($destination, $name); $member->cv = $destination . "/" . $name; } } $member->save(); if ($mode == 0) { $record = Member::find($id)->records; foreach ($record as $rec) { $rec->delete(); } } $recordArray = $request->input('rec'); if (!empty($recordArray)) { foreach ($recordArray as $key) { if (empty($key['delete'])) { $key['delete'] = 'off'; } if ($key['delete'] != "on" && $key['institute'] != "") { $record = new Record(); $record->institute = $key['institute']; $record->position = $key['position']; $record->start = $key['start']; $record->end = $key['end']; $record->type = $key['type']; $member->records()->save($record); } } } // $cat = Category::where('title', '=', $request->input('category'))->first(); return redirect('admin'); } } elseif ($type == 'researches') { $validator = Validator::make($request->all(), ['author' => 'required', 'title' => 'required', 'abstract' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput()->with(array('errorcode' => 'researches', 'tags' => $this->returnTags())); } else { if ($mode == 1) { $research = new Research(); $content = new Content(); } else { $research = Research::find($id); $content = $research->content; } $content->title = $request->input('title'); $content->body = $request->input('abstract'); $content->type = $type; $content->save(); $research->author = $request->input('author'); $research->publisher = $request->input('publisher') == NULL ? NULL : $request->input('publisher'); $date = $request->input('date-year') . "|" . $request->input('date-month') . "|" . $request->input('date-day') . "|" . $request->input('date-hour') . ":" . $request->input('date-minute'); $research->date = $date; $research->external = $request->input("external") == NULL ? true : false; $research->pages = $request->input('pages') == NULL ? NULL : $request->input('pages'); // $research->abstract = $request->input('abstract') == NULL ? NULL : $request->input('abstract'); $research->keywords = $request->input('keywords') == NULL ? NULL : $request->input('keywords'); $research->link = $request->input('link') == NULL ? NULL : $request->input('link'); $path = $request->file('path'); if (!empty($path) && $path->isValid()) { $tempName = $path->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . time() . "." . $extension[count($extension) - 1]; $destination = 'upload'; $path->move($destination, $name); $research->path = $destination . "/" . $name; } if (!empty($tag)) { foreach ($tag as $insertTag) { $row = Tag::where('title', '=', $insertTag)->first(); $content->tags()->save($row); } } $research->content()->associate($content); $research->save(); $cat = Category::where('title', '=', $request->input('category'))->first(); if ($cat != null) { $content->categories()->attach($cat->id); } return redirect('admin'); } } elseif ($type == 'galleries') { $validator = Validator::make($request->all(), ['title' => 'required', 'body' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput()->with(array('errorcode' => 'galleries', 'tags' => $this->returnTags())); } else { if ($mode == 1) { $content = new Content(); } else { $content = Content::find($id); } $content->title = $request->input('title'); $content->body = $request->input('body'); $content->type = $type; $content->save(); if ($request->hasFile('img')) { $file = $request->file('img'); for ($i = 0; $i < count($file); $i++) { if ($file[$i]->isValid()) { $photo = new Photo(); $tempName = $file[$i]->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . (string) $i . "." . $extension[count($extension) - 1]; $destination = 'upload'; $file[$i]->move($destination, $name); $photo->title = $request->input('imgtitle')[$i]; $photo->path = $destination . "/" . $name; $photo->highlight = $request->input("highlight")[$i] == "true" ? 1 : 0; $content->photos()->save($photo); } } } if ($mode != 1) { if (!empty($request->input('oldimg'))) { foreach ($request->input('oldimg') as $img) { if (empty($img['delete'])) { $img['delete'] = "off"; $image = Photo::find($img['id']); $image->title = $img['title']; $image->highlight = $img['highlight'] == "true" ? 1 : 0; $image->save(); } if ($img['delete'] == "on") { $temp = Photo::find($img['id']); $temp->delete(); } } } } if (!empty($tag)) { foreach ($tag as $insertTag) { $row = Tag::where('title', '=', $insertTag)->first(); $content->tags()->save($row); } } $cat = Category::where('title', '=', $request->input('category'))->first(); if ($cat != null) { $content->categories()->attach($cat->id); } return redirect('admin'); } } elseif ($type == 'tags') { $input = $request->all(); $split = explode("#", $input['body']); for ($i = 0; $i < count($split); $i++) { if (!empty($split[$i]) && $split[$i] != '') { $tag = new Tag(); $tag->title = trim($split[$i]); $tag->save(); } } return redirect('admin'); } elseif ($type == 'categories') { $cat = new Category(); $cat->title = $request->input("title"); $cat->parent = $request->input("cat-id"); if ($cat->parent == 0) { $cat->parent = null; } $cat->save(); return redirect('admin'); } elseif ($type == "variables") { $var = Variable::find($id); $var->title = $request->input("title"); $var->subtitle = $request->input("subtitle"); $var->body = $request->input("body"); if ($request->hasFile('img')) { $file = $request->file('img'); if ($file->isValid()) { $tempName = $file->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . "." . $extension[count($extension) - 1]; $destination = 'upload'; $file->move($destination, $name); //$photo->title = $request->input('photoTitle'); $var->body = $destination . "/" . $name; } } $var->save(); return redirect('admin'); } else { $validator = Validator::make($request->all(), ['title' => 'required', 'body' => 'required', 'tags' => 'required|array']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput()->with(array('errorcode' => 'news', 'tags' => $this->returnTags())); } else { if ($mode == 1) { $news = new Content(); } else { $news = Content::find($id); } $news->title = $request->input('title'); $news->body = $request->input('body'); $news->type = $type; $news->save(); if ($request->hasFile('img')) { $files = $request->file('img'); if ($mode == 0) { $oldphoto = Photo::where("content_id", $id)->first(); $oldphoto->delete(); } foreach ($files as $file) { if ($file->isValid()) { $photo = new Photo(); $tempName = $file->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . "." . $extension[count($extension) - 1]; $destination = 'upload'; $file->move($destination, $name); //$photo->title = $request->input('photoTitle'); $photo->path = $destination . "/" . $name; $news->photos()->save($photo); } } } if (!empty($tag)) { foreach ($tag as $insertTag) { $row = Tag::where('title', '=', $insertTag)->first(); $news->tags()->save($row); } } $cat = Category::find($request->input('cat-id')); if ($cat != null) { $news->categories()->attach($cat->id); } return redirect('admin'); } } }
/** * */ public function getConfirmDelete($photo_id) { $photo = \App\Photo::find($photo_id); $count = \App\Photo::where('landmark_id', '=', $photo->landmark_id)->count(); if ($count == 1) { \Session::flash('flash_message', 'This is the last photo of the landmark. We can\'t delete the last photo!'); return redirect('\\photos'); } return view('photos.delete')->with('photo', $photo); }