public function delete(Request $request) { $photo = Photo::find($request->input('id')); if (File::exists($photo->image_url)) { File::delete($photo->image_url); } $photo->delete(); return response()->json(['success' => true, 'message' => "Изображение успешно удалено."]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Photo::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'artist_id' => $this->artist_id, 'file_id' => $this->file_id, 'is_main' => $this->is_main]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Photo::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['idphoto' => $this->idphoto]); $query->andFilterWhere(['like', 'photo', $this->photo])->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Photo::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'width' => $this->width, 'heigth' => $this->heigth]); $query->andFilterWhere(['like', 'reference', $this->reference])->andFilterWhere(['like', 'place_id', $this->place_id]); return $dataProvider; }
public function ajaxDel(Request $request, $id) { if ($request->ajax()) { $photo = Photo::find($id); $photo->delete(); //unlink( imageURLToName($image_file->uri) ); $json = ['status' => 1, 'info' => '删除成功']; return response()->json($json); } else { return ''; //return response()->json($json); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $photo = \App\Models\Photo::find($id); $photo->delete(); return redirect('allPhotos'); }
public function getDelete($id) { $user = User::findOrFail($id); if (!empty($user->photo_id)) { $photo = Photo::find($user->photo_id); $imgName = $photo->photo_name; $fullPath = base_path() . $this->storagePath . $imgName; //deleting @unlink($fullPath); $photo->delete(); } if ($user->delete()) { Session::flash('message', "User {$user->name} was deleted"); } else { Session::flash('message', "To delete user {$user->name} failed"); } return redirect()->action('AdminController@getIndex'); }
public function actionViewAlbum($id) { if (Yii::$app->deviceDetect->isMobile()) { $this->layout = "//mobile"; $mobile = 'mobile/'; } else { $this->layout = "//inner"; $mobile = ''; } $album = Photo::findOne($id); $next_album = Photo::find()->where(['page_id' => $album->page_id, 'parent_id' => 0])->andWhere(['>', 'id', $album->id])->orderBy(['create_date' => SORT_DESC])->one(); $prev_album = Photo::find()->where(['page_id' => $album->page_id, 'parent_id' => 0])->andWhere(['<', 'id', $album->id])->orderBy(['create_date' => SORT_DESC])->one(); $page = $album->page; if ($page->parent_id == 0) { $menu = Page::find()->where(['parent_id' => $page->id])->all(); } else { $menu = Page::find()->where(['parent_id' => $page->parent_id])->all(); } $photos = Photo::find()->where(['parent_id' => $id])->orderBy(['order' => SORT_ASC])->all(); return $this->render($mobile . 'template/album', ['menu' => $menu, 'album' => $album, 'next_album' => $next_album, 'prev_album' => $prev_album, 'photos' => $photos]); }
public function actionHome() { $request = Yii::$app->request; $page_id = $request->get('page_id'); $photo = Photo::find()->where(['page_id' => $page_id])->orderBy('create_date desc')->one(); $request = Yii::$app->request; $model = new UploadForm(); if (Yii::$app->request->isPost) { $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles'); if ($model->upload()) { $date = date("Ymd", time()); foreach ($model->imageFiles as $key => $image) { $path = '/uploads/picnews/' . $date . '/'; $photo = new Photo(); $photo->path = $path . $image->baseName . '.' . $image->extension; $photo->page_id = $page_id; $photo->parent_id = 0; $photo->create_date = time(); $photo->update_date = time(); $photo->save(); } return $this->redirect(['home', 'page_id' => $page_id]); } } else { return $this->render('home', ['model' => $model, 'photo' => $photo]); } }
/** * If an article not have cover, replace by its tagged destination's image * @return string URL of article cover image */ public function getThumbnailAttribute() { /** @var Photo $thumbPhoto */ try { $thumbPhoto = $this->cover_id != null ? Photo::find($this->cover_id) : $this->first_related_destination->avatar; return $thumbPhoto->src; } catch (\Exception $e) { return Photo::samplePhotoUrl(); } }
/** * Remove the specified resource from storage. * * @return \Illuminate\Http\Response */ public function postDestroy() { if ($this->request->ajax()) { $id = $this->request['id'] ?: ''; $data = Photo::find($id); if ($data) { $data->delete(); } $response = array('url' => route('photo.index')); return $response; } }
/** * Returns User's Gallery Photos * * @param type $user_id User's ID * * @return array array of photos (urls) */ public static function getGallery($user_id) { $data = Photo::find()->select('filename')->where(['user_id' => $user_id])->andWhere(['type' => 'gallery'])->all(); $dt = []; foreach ($data as $var) { $dt[] = (new Image($var->filename, new ImageTypes(ImageTypes::GalleryPhoto), new ImgMediaLoc()))->getImage(); } return $dt; }