Пример #1
0
 /**
  * @param $aid
  * @return \Response
  * @throws \Exception
  */
 public function loadAudio($aid)
 {
     $attachment = Attachment::findOrFail($aid);
     $response = Vk::call('audio.getById', ['audios' => $attachment->external_id]);
     $audio = reset($response['response']);
     return response()->json(['url' => $audio['url']]);
 }
Пример #2
0
 public function destroy($employeeId, $attachmentId)
 {
     $attachment = Attachment::findOrFail($attachmentId);
     //TODO::doesnt work for some reason
     \File::delete($attachment->location);
     $attachment->delete();
     return redirect()->to('/hr/employee/' . $employeeId);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param \Illuminate\Http\Request $request
  * @param  int                     $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $attachment = \App\Attachment::findOrFail($id);
     $path = attachment_path($attachment->name);
     if (\File::exists($path)) {
         \File::delete($path);
     }
     $attachment->delete();
     if ($request->ajax()) {
         return response()->json('', 204);
     }
     flash()->success(trans('forum.deleted'));
     return back();
 }
 public function destroy(Request $request)
 {
     $attachmentId = $request->get('key');
     $filePath = $request->get('path');
     DB::transaction(function () use($attachmentId) {
         $user = Auth::user();
         $attachment = Attachment::findOrFail($attachmentId);
         $attachment->updated_by = $user->name;
         $attachment->deleted_by = $user->name;
         $attachment->save();
         $filePath = $attachment->path;
         // soft delete
         $attachment->delete();
     });
     if (!is_null($filePath)) {
         Storage::disk('image')->delete(str_replace('/uploads/', '', $filePath));
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     // validate request
     $validateProductColor = Validator::make($request->get('ProductColor'), ProductColor::$rules);
     $validationMessages = [];
     foreach ($request->get('ProductColorTranslation') as $key => $value) {
         $validateProductColorTranslation = Validator::make($value, ProductColorTranslation::$rules);
         if ($validateProductColorTranslation->fails()) {
             $validationMessages = array_merge_recursive($validationMessages, $validateProductColorTranslation->messages()->toArray());
         }
     }
     if ($validateProductColor->fails() or count($validationMessages) > 0) {
         $validationMessages = array_merge_recursive($validateProductColor->messages()->toArray(), $validationMessages);
         return redirect()->back()->withErrors($validationMessages)->withInput();
     }
     // get all languages
     $languages = Language::all();
     // find language default
     $languageDefault = $languages->where('is_key_language', 1)->first();
     if (is_null($languageDefault)) {
         $languageDefault = $languages->first();
     }
     // sure execute success, if not success rollback
     DB::transaction(function () use($request, $id, $languageDefault) {
         $user = $request->user();
         // insert ProductColor
         $productColor = ProductColor::findOrFail($id);
         $productColor->key = Common::createKeyURL($request->input('ProductColorTranslation.' . $languageDefault->code . '.name'));
         $productColor->parent_id = $request->input('ProductColor.parent_id');
         $productColor->priority = $request->input('ProductColor.priority');
         $productColor->is_publish = $request->input('ProductColor.is_publish');
         $productColor->created_by = $user->name;
         $productColor->updated_by = $user->name;
         $productColor->save();
         // save attachments
         // only insert or delete, not update
         if ($request->input('ProductColor.attachments') != "") {
             $currentAttachments = $productColor->attachments->lists('id');
             $requestAttachments = explode(',', $request->input('ProductColor.attachments'));
             $attachments = [];
             $keepAttachments = [];
             foreach ($requestAttachments as $key => $value) {
                 if (strpos($value, '|') === false) {
                     array_push($attachments, new Attachment(['entry_id' => $productColor->id, 'table_name' => 'product_colors', 'path' => $value, 'priority' => 0, 'is_publish' => 1]));
                 } else {
                     $attachmentId = explode('|', $value)[0];
                     array_push($keepAttachments, $attachmentId);
                 }
             }
             if (count($attachments) > 0) {
                 $productColor->attachments()->saveMany($attachments);
             }
             // delete attachments
             foreach ($currentAttachments as $key => $value) {
                 if (!in_array($value, $keepAttachments)) {
                     Attachment::findOrFail($value)->delete();
                 }
             }
         }
         // save data languages
         foreach ($request->get('ProductColorTranslation') as $locale => $value) {
             $productColor->translateOrNew($locale)->name = $request->input('ProductColorTranslation.' . $locale . '.name');
             $productColor->translateOrNew($locale)->summary = $request->input('ProductColorTranslation.' . $locale . '.summary');
             $productColor->translateOrNew($locale)->meta_description = $request->input('ProductColorTranslation.' . $locale . '.meta_description');
             $productColor->translateOrNew($locale)->meta_keywords = $request->input('ProductColorTranslation.' . $locale . '.meta_keywords');
         }
         $productColor->save();
     });
     return redirect()->route('admin.productcolors.index');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     // validate request
     $validateProjectCategory = Validator::make($request->get('ProjectCategory'), ProjectCategory::$rules);
     $validationMessages = [];
     if ($validateProjectCategory->fails() or count($validationMessages) > 0) {
         $validationMessages = array_merge_recursive($validateProjectCategory->messages()->toArray(), $validationMessages);
         return redirect()->back()->withErrors($validationMessages)->withInput();
     }
     // sure execute success, if not success rollback
     DB::transaction(function () use($request, $id) {
         $user = $request->user();
         // insert ProjectCategory
         $projectCategory = ProjectCategory::findOrFail($id);
         $projectCategory->key = Common::createKeyURL($request->input('ProjectCategory.name'));
         $projectCategory->parent_id = $request->input('ProjectCategory.parent_id');
         $projectCategory->priority = $request->input('ProjectCategory.priority');
         $projectCategory->name = $request->input('ProjectCategory.name');
         $projectCategory->summary = $request->input('ProjectCategory.summary');
         $projectCategory->meta_description = $request->input('ProjectCategory.meta_description');
         $projectCategory->meta_keywords = $request->input('ProjectCategory.meta_keywords');
         $projectCategory->active = $request->input('ProjectCategory.active');
         $projectCategory->created_by = $user->name;
         $projectCategory->updated_by = $user->name;
         $projectCategory->save();
         // save attachments
         // only insert or delete, not update
         if ($request->input('ProjectCategory.attachments') != "") {
             $currentAttachments = $projectCategory->attachments->lists('id');
             $requestAttachments = explode(',', $request->input('ProjectCategory.attachments'));
             $attachments = [];
             $keepAttachments = [];
             foreach ($requestAttachments as $key => $value) {
                 if (strpos($value, '|') === false) {
                     array_push($attachments, new Attachment(['entry_id' => $projectCategory->id, 'table_name' => 'project_categories', 'path' => $value, 'priority' => 0, 'active' => 1]));
                 } else {
                     $attachmentId = explode('|', $value)[0];
                     array_push($keepAttachments, $attachmentId);
                 }
             }
             if (count($attachments) > 0) {
                 $projectCategory->attachments()->saveMany($attachments);
             }
             // delete attachments
             foreach ($currentAttachments as $key => $value) {
                 if (!in_array($value, $keepAttachments)) {
                     Attachment::findOrFail($value)->delete();
                 }
             }
         }
     });
     return redirect()->route('admin.projectcategories.index');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     // validate request
     $validateProduct = Validator::make($request->get('Product'), Product::$rules);
     $validationMessages = [];
     if ($validateProduct->fails() or count($validationMessages) > 0) {
         $validationMessages = array_merge_recursive($validateProduct->messages()->toArray(), $validationMessages);
         return redirect()->back()->withErrors($validationMessages)->withInput();
     }
     // sure execute success, if not success rollback
     DB::transaction(function () use($request, $id) {
         $user = $request->user();
         // insert Product
         $product = Product::findOrFail($id);
         $product->key = Common::createKeyURL($request->input('Product.title'));
         $product->title = $request->input('Product.title');
         $product->product_type_id = $request->input('Product.product_type_id');
         $product->province_id = $request->input('Product.province_id');
         $product->district_id = $request->input('Product.district_id');
         $product->ward_id = $request->input('Product.ward_id');
         $product->street_id = $request->input('Product.street_id');
         $product->project_id = $request->input('Product.project_id');
         $product->price_range_id = $request->input('Product.price_range_id');
         $product->area_range_id = $request->input('Product.area_range_id');
         $product->incense_type_id = $request->input('Product.incense_type_id');
         $product->area = $request->input('Product.area');
         $product->price = $request->input('Product.price');
         $product->price_type_id = $request->input('Product.price_type_id');
         $product->total_price = $request->input('Product.total_price');
         $product->address = $request->input('Product.address');
         if ($request->input('Product.expire_at') != null && $request->input('Product.expire_at') != '') {
             $expire_at = Carbon::createFromFormat('d/m/Y', $request->input('Product.expire_at'))->toDateString();
             $product->expire_at = $expire_at;
         }
         $product->summary = $request->input('Product.summary');
         $product->description = $request->input('Product.description');
         $product->home_direction = $request->input('Product.home_direction');
         $product->rooms = $request->input('Product.rooms');
         $product->toilets = $request->input('Product.toilets');
         $product->interior = $request->input('Product.interior');
         $product->main_image = $request->input('Product.main_image');
         $product->br_name = $request->input('Product.br_name');
         $product->br_address = $request->input('Product.br_address');
         $product->br_phone = $request->input('Product.br_phone');
         $product->br_email = $request->input('Product.br_email');
         $product->map_latitude = $request->input('Product.map_latitude');
         $product->map_longitude = $request->input('Product.map_longitude');
         $product->meta_description = $request->input('Product.meta_description');
         $product->meta_keywords = $request->input('Product.meta_keywords');
         $product->priority = $request->input('Product.priority');
         $product->active = $request->input('Product.active');
         $product->user_id = $user->id;
         $product->created_by = $user->name;
         $product->updated_by = $user->name;
         $product->save();
         // save attachments
         // only insert or delete, not update
         if ($request->input('Product.attachments') != "") {
             $currentAttachments = $product->attachments->lists('id');
             $requestAttachments = explode(',', $request->input('Product.attachments'));
             $attachments = [];
             $keepAttachments = [];
             foreach ($requestAttachments as $key => $value) {
                 if (strpos($value, '|') === false) {
                     array_push($attachments, new Attachment(['entry_id' => $product->id, 'table_name' => 'products', 'path' => $value, 'priority' => 0, 'is_publish' => 1]));
                 } else {
                     $attachmentId = explode('|', $value)[0];
                     array_push($keepAttachments, $attachmentId);
                 }
             }
             if (count($attachments) > 0) {
                 $product->attachments()->saveMany($attachments);
             }
             // delete attachments
             foreach ($currentAttachments as $key => $value) {
                 if (!in_array($value, $keepAttachments)) {
                     Attachment::findOrFail($value)->delete();
                 }
             }
         }
         $product->save();
     });
     return redirect()->route('admin.products.index');
 }