protected static function boot() { parent::boot(); static::creating(function ($model) { $data = array('name' => $model->name, 'type_id' => $model->type_id, 'description' => $model->description, 'info_specialties' => $model->info_specialties, 'contacts' => $model->contacts, 'cover_photo' => $model->cover_photo, 'financing_id' => $model->financing_id, 'specialties' => $model->set_specialties, 'city_id' => $model->city_id); $rules = array('name' => 'required|min:3|max:100', 'type_id' => 'required|min:1|max:300000', 'description' => 'required|min:10', 'info_specialties' => 'min:10', 'contacts' => 'required|min:10', 'cover_photo' => 'required|image', 'financing_id' => 'required|min:1|max:300000', 'specialties' => 'array', 'city_id' => 'required|min:1|max:300000'); $validator = Validator::make($data, $rules); if ($validator->fails()) { throw new ValidationException(null, null, null, $validator->messages()); } else { return $model->validate(); } }); static::created(function ($model) { if (!is_array($model->set_specialties)) { $model->set_specialties = [$model->set_specialties]; } $model->specialty()->sync($model->set_specialties); if (Auth::user()->hasRole('admin') || Auth::user()->hasRole('moderator')) { $model->update(array('status' => true)); } else { $model->makeLoggedUserModerator(); } }); static::updating(function ($model) { $data = array('name' => $model->name, 'type_id' => $model->type_id, 'description' => $model->description, 'info_specialties' => $model->info_specialties, 'contacts' => $model->contacts, 'financing_id' => $model->financing_id, 'city_id' => $model->city_id); $rules = array('name' => 'required|min:3|max:100', 'type_id' => 'required|min:1|max:300000', 'description' => 'required|min:10', 'info_specialties' => 'min:10', 'contacts' => 'required|min:10', 'financing_id' => 'required|min:1|max:300000', 'city_id' => 'required|min:1|max:300000'); $validator = Validator::make($data, $rules); if ($validator->fails()) { throw new ValidationException(null, null, null, $validator->messages()); } return true; }); static::deleting(function ($model) { $destination_path = public_path() . '/storage/cover_photos/'; $thumbnail_path = public_path() . '/storage/cover_photos/thumbnails/'; $cover_info = pathinfo($destination_path . $model->cover_name); $old_cover_retina = $destination_path . $cover_info['filename'] . '@2x.' . $cover_info['extension']; $old_thumb_retina = $thumbnail_path . $cover_info['filename'] . '@2x.' . $cover_info['extension']; File::delete($destination_path . $model->cover_name); File::delete($thumbnail_path . $model->cover_name); File::delete($old_cover_retina); File::delete($old_thumb_retina); $galleries = Gallery::where('school_id', '=', $model->id)->get(); foreach ($galleries as $gallery_photo) { $gallery = Gallery::find($gallery_photo->id)->delete(); } $visitor_comments = VisitorComments::where('school_id', '=', $model->id)->delete(); $visitor_likes = VisitorLikes::where('school_id', '=', $model->id)->delete(); return true; }); static::deleted(function ($model) { $model->users()->sync(array()); }); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $gallery = Gallery::find($id); if (!is_null($gallery)) { if ($gallery->delete()) { return Redirect::route('admin.galleries.edit', array($gallery->school_id))->withErrors(array('mainSuccess' => 'Снимката е успешно изтрита от галерията.')); } else { return Redirect::route('admin.galleries.edit', array($gallery->school_id))->withErrors(array('mainError' => 'Грешка с базата данни.')); } } else { return Redirect::route('admin.galleries.index')->withErrors(array('mainError' => 'Галерията не е намерена.')); } }
public function post_edit() { $rules = array('id' => 'required|exists:gallery', 'title' => 'required|max:255'); $validation = Validator::make(Input::all(), $rules); if ($validation->fails()) { Messages::add('error', $validation->errors->all()); return Redirect::to('admin/' . $this->views . '/edit')->with_input(); } else { $gallery = Gallery::find(Input::get('id')); $gallery->title = Input::get('title'); $gallery->description = Input::get('description'); $gallery->created_by = $this->data['user']->id; $gallery->save(); Messages::add('success', 'Gallery Saved'); return Redirect::to('admin/' . $this->views . ''); } }
public function initialize($entity = null, $options = null) { $category = new Select('categoryid', DishCategory::find(), array('using' => array('id', 'category'), 'useEmpty' => TRUE, 'emptyText' => 'Seleccione una Categoria')); $category->setLabel('Category'); $this->add($category); $gallery = new Select('galleryid', Gallery::find(), array('using' => array('id', 'name'), 'useEmpty' => TRUE, 'emptyText' => 'Seleccione una galeria')); $gallery->setLabel('Galeria'); $this->add($gallery); $name = new Text('name'); $name->setLabel('Name'); $this->add($name); $price = new Text('price'); $price->setLabel('Price'); $this->add($price); $image_path = new Text('image_path'); $image_path->setLabel('Image'); $this->add($image_path); $description = new TextArea('description'); $description->setLabel('Description'); $this->add($description); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($order) { $success = 'not sure !'; // delete $image = Image::where('gallery_id', '=', Input::get('gallery_id'))->where('order', '=', $order)->first(); if (empty($image)) { return Redirect::to('admin/gallery/' . Input::get('gallery_id'))->with('error', 'Cette image n\'existe pas !'); } $gallery = Gallery::find(Input::get('gallery_id')); if ($image->id == $gallery->cover_id) { $success = 'Vous avez supprimé la Cover de la Galerie ! Elle a été remplacé par la première image.'; } //Regulation order in image $image->delete(); DB::table('images')->where('gallery_id', '=', Input::get('gallery_id'))->where('order', '>', $order)->decrement('order'); if ($image->id == $gallery->cover_id) { $gallery->cover_id = Image::where('gallery_id', '=', Input::get('gallery_id'))->where('order', '=', 0)->first()->id; $gallery->save(); } // redirect $success .= ' L\'image a été supprimé !'; return Redirect::to('admin/gallery/' . Input::get('gallery_id'))->with('success', $success); }
public function postAddNewImage() { $data = Input::only('id', 'name', 'category', 'position', 'updatedby', 'slidefile'); if ($data['id']) { $gallery = Gallery::find($data['id']); } else { $gallery = new Gallery(); } $gallery->name = $data['name']; $gallery->category = $data['category']; $gallery->position = $data['position']; $gallery->updatedby = $data['updatedby']; $file = Input::file('slidefile'); if ($file) { $name = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $newfilename = uniqid(md5(rand(00, 9999) . $name)) . '.' . $extension; $image = Image::make($_FILES['slidefile']['tmp_name'])->resize(900, 700)->save('uploads/' . $newfilename, 100); $gallery->imageurl = 'uploads/' . $newfilename; } $gallery->save(); return Redirect::to('/admin/photogallery/list'); }
/** * Store a newly created resource in storage. * * @param MenuRequest $request * @return \Illuminate\Http\Response */ public function store(MenuRequest $request) { // content input $menu['title'] = \Input::get('title'); $menu['eng_title'] = \Input::get('eng_title'); $menu['subtitle'] = \Input::get('subtitle'); $menu['eng_subtitle'] = \Input::get('eng_subtitle'); $menu['slug'] = '/' . \trslug::trslug($menu['title']); $menu['eng_slug'] = '/eng/' . \trslug::trslug($menu['eng_title']); $menu['header'] = \Input::get('header'); $menu['active'] = \Input::get('active') === "1"; $menu['body'] = \Input::get('body'); $menu['eng_body'] = \Input::get('eng_body'); $menu['line'] = 999; $menu = Menu::create($menu); $this->rebuild(); // content polymorphic relations //banner relations if (\Input::get('banner')) { foreach (\Input::get('banner') as $banner) { Banner::find($banner)->menus()->save($menu); } } //gallery relations if (\Input::get('gallery')) { foreach (\Input::get('gallery') as $gallery) { Gallery::find($gallery)->menus()->save($menu); } } //linkTitles relations if (\Input::get('linkTitle')) { foreach (\Input::get('linkTitle') as $linkTitle) { LinkTitle::find($linkTitle)->menus()->save($menu); } } return \Redirect::back()->with('message', 'Kaydedildi'); }
public static function renameGallery($gallery_id = false, $name = false) { if (!$gallery_id || !$name) { return false; } $gallery = Gallery::find($gallery_id); if (is_object($gallery)) { $gallery->name = $name; $gallery->save(); return true; } return false; }
public function deletePhotoGallery() { $id = Input::get('imgId'); $galleryPhoto = Gallery::find($id); if ($galleryPhoto->delete()) { return 1; } else { return 0; } }
public function getDelete($type, $type_id, $id) { switch ($type) { case 'page': $posts = Post::where('type_id', '=', $type_id)->where('id', '=', $id)->delete(); $redir = '/admin/content/' . $type_id; break; case 'slide': $slide = Slider::find($id)->delete(); $redir = '/admin/slider'; break; case 'user': $slide = User::find($id)->delete(); $redir = '/admin/user'; break; case 'image': $slide = Gallery::find($id); if (file_exists($slide->image)) { unlink($slide->image); } if (file_exists($slide->small_image)) { unlink($slide->small_image); } $slide->delete(); return Redirect::back(); break; } return Redirect::to($redir); }
public function post_addimage() { $gallery = Gallery::find($this->gallery_id); $new_image = array('gallery_id' => $gallery->id, 'url' => trim(Input::get('url')), 'url_thumb' => trim(Input::get('url_thumb')), 'title' => trim(Input::get('title')), 'alt' => trim(Input::get('alt')), 'description' => trim(Input::get('description')), 'type' => trim(Input::get('type')), 'sort_order' => trim(Input::get('sort_order')), 'visibility' => trim(Input::get('visible'))); // set up rules for new data $rules = array('url' => 'required', 'url_thumb' => 'required', 'title' => 'required'); // make the validator $v = Validator::make($new_image, $rules); if ($v->fails()) { // redirect to form // errors return Redirect::to('user/galleries/addimage/' . $gallery->id)->with_errors($v)->with_input(); } // create the new image $image = new Image($new_image); $image->save(); // redirect to gallery return Redirect::to('user/galleries/view/' . $gallery->id)->with('success', 'A new image has been added'); }
Route::post('/add', array('uses' => 'RainGalleryContent@postAddNewImage')); # Admin List photo Route::get('/list', function () { $user = Sentry::getUser(); $galleryImages = Gallery::get(); return View::make('backend.photolist')->with('user', $user)->with('galleryimg', $galleryImages); }); # Admin Edit category Route::get('/edit/{id}', function ($id) { $user = Sentry::getUser(); $editVarsdata = Gallery::find($id); return View::make('backend.photoadd')->with('edit', true)->with('editData', $editVarsdata)->with('user', $user); }); Route::get('/delete/{id}', function ($id) { $user = Sentry::getUser(); $getDelData = Gallery::find($id); if ($getDelData) { $getDelData->delete(); } return Redirect::to('/admin/photogallery/list'); }); }); // Admin Panel | HomeSlides Route::group(array('before' => 'admin.login', 'prefix' => 'admin/homeslide'), function () { # Admin Add New Home Slides; Route::get('/add', function () { $user = Sentry::getUser(); return View::make('backend.homeslides')->with('user', $user); }); Route::post('/add', array('uses' => 'RainCHSlideController@postAddhomeslide')); # Admin Edit Videos
public function TitleSave($id) { //$gallery = Gallery::find($id); $input_value = array('title' => Input::get('text')); $input_check = array('title' => array('required')); $validator = Validator::make($input_value, $input_check); if ($validator->fails()) { $error = $validator->messages()->toArray(); $gallery = Gallery::all(); return View::make('admin.gallery.gallery')->with('gallery_img', $gallery)->with('error_gallery', $error); } else { $gallery = Gallery::find($id); $gallery->title = Input::get('text'); $gallery->save(); if ($gallery->save()) { $gallery = Gallery::all(); return View::make('admin.gallery.gallery')->with('gallery_img', $gallery)->with('edit_gallery_save', ''); } } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $gallery = Gallery::find($id); $gallery->delete(); return View::make('gallery.manage'); }
if (!empty($search)) { $search_faqs = $organisation->faqs()->where(function ($query) use($search) { $query->where('answer', 'LIKE', '%' . $search . '%')->or_where('question', 'LIKE', '%' . $search . '%'); })->order_by('sort_order', 'asc')->get(); } return View::make('pages.faqs')->with('faqs', $faqs)->with('search', $search)->with('search_faqs', $search_faqs); }); Route::get('/galleries/(:any)', function ($gallery) { $gallery = Gallery::where('slug', '=', $gallery)->first(); $organisation = Organisation::find(1); $images = $gallery->images; $galleries = $organisation->galleries()->order_by('sort_order', 'asc')->get(); return View::make('pages.gallery')->with('images', $images)->with('gallery', $gallery)->with('galleries', $galleries); }); Route::get('/videos', function () { $images = Gallery::find(2)->images; $organisation = Organisation::find(1); $galleries = $organisation->galleries()->order_by('sort_order', 'asc')->get(); return View::make('pages.videos')->with('images', $images)->with('galleries', $galleries); }); Route::get('/support', function () { $organisation = Organisation::find(1); $testimonials = $organisation->testimonials()->order_by(DB::raw('RAND()'))->take(2)->get(); $galleries = $organisation->galleries()->order_by('sort_order', 'asc')->get(); $title = 'Support | Booths Garden Studios'; // $description = ''; // $keywords = ''; return View::make('pages.support')->with('title', $title)->with('testimonials', $testimonials)->with('galleries', $galleries); }); Route::post('/support', function () { $organisation = Organisation::find(1);
/** * [deleteUserImage function used to delete photo in user's gallery] */ public function deleteUserImage() { $userid = Input::get('userid'); $photo = Gallery::find($userid); $photo->delete(); die; }