diff --git a/app/Http/Controllers/Admin/ManageFreeUInvestments/VentureCapitalFundController.php b/app/Http/Controllers/Admin/ManageFreeUInvestments/VentureCapitalFundController.php index e3821d5..b6a3c53 100644 --- a/app/Http/Controllers/Admin/ManageFreeUInvestments/VentureCapitalFundController.php +++ b/app/Http/Controllers/Admin/ManageFreeUInvestments/VentureCapitalFundController.php @@ -11,6 +11,7 @@ use Illuminate\Support\Str; use App\Models\AlternativeInvestmentFund; use App\Models\Product; use App\Models\Company; +use App\Models\ProductImage; use Illuminate\Support\Facades\Validator; class VentureCapitalFundController extends Controller @@ -81,7 +82,7 @@ class VentureCapitalFundController extends Controller public function edit($id) { $companies = Company::active()->pluck('company_name', 'id'); - $alternativeInvestmentFund = Product::with('category', 'alternativeInvestmentFund')->alternativeInvestmentFund()->find($id); + $alternativeInvestmentFund = Product::with('category', 'alternativeInvestmentFund','product_images')->alternativeInvestmentFund()->find($id); // dd($alternativeInvestmentFund); return view('Admin.Pages.manage_freeu_investment.edit-product.alternative-investment-fund', compact('alternativeInvestmentFund', 'companies')); } @@ -197,6 +198,41 @@ class VentureCapitalFundController extends Controller 'fact_sheet'=>$productfactsheet,]); } + if ($request->hasFile('images')) { + // dd($request->hasFile('images')); + // $edit_program_images = ProgramImage::where('programs_xid', $program_id)->delete(); + + foreach ($request->file('images') as $key => $file) { + $filename = date('YmdHi') . '_' . $file->getClientOriginalName(); + $file->move(public_path('assets/uploads/product_images'), $filename); + $images = 'assets/uploads/product_images/' . $filename; + $alternativeInvestmentFund = new ProductImage(); + $alternativeInvestmentFund->product_xid = $request->alternative_id; + $alternativeInvestmentFund->images = $images; + + $alternativeInvestmentFund->save(); + } + } + + $imagesToRemove = $request->input('images_to_remove')[0]; + // dd($imagesToRemove); + if (!empty($imagesToRemove)) { + $imagesToRemoveJson = $request->input('images_to_remove')[0]; + $imagesToRemove = json_decode($imagesToRemoveJson); + foreach ($imagesToRemove as $imageId) { + $userFile = ProductImage::find($imageId); + if ($userFile) { + $file_path = public_path($userFile->images); + if (file_exists($file_path)) { + unlink($file_path); + } + + // Delete the record from the database + $userFile->delete(); + } + } + } + $aif = AlternativeInvestmentFund::find($request->id); $type = Product::where('id',$aif->products_id)->update(['type' => $request->type]); @@ -213,4 +249,15 @@ class VentureCapitalFundController extends Controller { // } + + public function delete_image(Request $request){ + $image = ProductImage::find($request->image_id); + $previous_image = public_path($image->images); + File::delete($previous_image); + $image->id = $request->image_id; + $image->delete(); + return response()->json(['success' => true, 'status' => 200]); +// dd("requ",$request->all()); + + } } diff --git a/app/Models/Product.php b/app/Models/Product.php index 7c7b6dd..d54debe 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Models\Category; +use App\Models\ProductImage; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -352,6 +353,11 @@ class Product extends Model if ($value) return imagePath('public/uploads/real_estate/photos/') . $value; } + public function product_images() + { + return $this->hasMany(ProductImage::class,'product_xid','id'); + } + // public function scopeGetAllDetails($query) // { diff --git a/app/Models/ProductImage.php b/app/Models/ProductImage.php new file mode 100644 index 0000000..1399850 --- /dev/null +++ b/app/Models/ProductImage.php @@ -0,0 +1,13 @@ + + .img-thumbs { + background: #eee; + border: 1px solid #ccc; + border-radius: 0.25rem; + margin: 1.5rem 0; + padding: 0.75rem; + } + .img-thumbs-hidden { + display: none; + } + + .edit_wrapper-thumb, .wrapper-thumb { + position: relative; + display:inline-block; + /*margin: 1rem 0;*/ + justify-content: space-around; + } + + .img-preview-thumb { + background: #fff; + border: 1px solid none; + border-radius: 0.25rem; + box-shadow: 0.125rem 0.125rem 0.0625rem rgba(0, 0, 0, 0.12); + margin-right: 1rem; + max-width: 140px; + padding: 0.25rem; + } +
@@ -1044,6 +1074,46 @@
+ {{--
+ +
+ +
+ + @if(isset($alternativeInvestmentFund['product_images']) && count($alternativeInvestmentFund['product_images']) > 0) +
+ @foreach($alternativeInvestmentFund['product_images'] as $image) +
+ Image {{ $image['id'] }} + x +
+ @endforeach +
+ @endif +
--}} + +
+ +
+ +
+ + @if(isset($alternativeInvestmentFund['product_images']) && count($alternativeInvestmentFund['product_images']) > 0) +
+ @foreach($alternativeInvestmentFund['product_images'] as $image) +
+ Image {{ $image['id'] }} + x +
+ @endforeach +
+ @endif +
+ @@ -1643,6 +1713,145 @@ }, }); + + //**************************************************************** Multi image uploding start ******************************************************************* + var imgUpload = document.getElementById('upload-img') + , imgPreview = document.getElementById('img-preview') + , imgUploadForm = document.getElementById('form-upload') + , totalFiles + , previewTitle + , previewTitleText + , img; + + imgUpload.addEventListener('change', previewImgs, true); + + function previewImgs(event) { + totalFiles = imgUpload.files.length; + + if (!!totalFiles) { + imgPreview.classList.remove('img-thumbs-hidden'); + } + + for (var i = 0; i < totalFiles; i++) { + wrapper = document.createElement('div'); + wrapper.classList.add('wrapper-thumb'); + removeBtn = document.createElement("span"); + nodeRemove = document.createTextNode('x'); + removeBtn.classList.add('remove-btn'); + removeBtn.appendChild(nodeRemove); + img = document.createElement('img'); + img.src = URL.createObjectURL(event.target.files[i]); + img.classList.add('img-preview-thumb'); + wrapper.appendChild(img); + wrapper.appendChild(removeBtn); + imgPreview.appendChild(wrapper); + $('.remove-btn').click(function () { + $(this).parent('.wrapper-thumb').remove(); + }); + } + } +//**************************************************************** Multi image uploding end ******************************************************************* + +// $('.edit_remove-btn').on("click", function () { +// // let url_path = base_url; +// var image_id = $(this).data("image_id"); +// var image_path = $(this).data("image_path"); +// // alert(image_path); + +// // Remove the image preview from the DOM +// $(this).closest('.edit_wrapper-thumb').remove(); + +// // Update the hidden input field to include the image path for deletion +// var imagesToRemove = $('#images-to-remove').val(); +// if (imagesToRemove) { +// imagesToRemove += ',' + image_path; +// } else { +// imagesToRemove = image_path; +// } +// $('#images-to-remove').val(imagesToRemove); + +// // Ask for confirmation +// if (confirm("Are you sure you want to delete this image?")) { +// $.ajaxSetup({ +// headers: { +// "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), +// } +// }); + +// $.ajax({ +// type: "DELETE", +// dataType: "json", +// url: "{{route('delete_image')}}", +// data: { +// image_id: image_id, +// image_path: image_path, +// }, +// success: function (response) { +// if (response.status == 200) { +// toastr.success('Image Deleted Successfully'); +// setTimeout(function () { +// // Redirect or perform any other action after successful deletion. +// // window.location.href = url_path + "/programe_edit"; +// }, 1000); +// } else { +// toastr.error("Something went wrong"); +// } +// }, +// }); +// } +// }); + +$('.edit_remove-btn').on("click", function () { + var image_id = $(this).data("image_id"); + var image_path = $(this).data("image_path"); + + var imagesToRemove = $('#images-to-remove'); + +// Get the current value and parse it as an array +var removedImages = imagesToRemove.val() ? JSON.parse(imagesToRemove.val()) : []; + +// Only push to the array if the imageId is not null +if (image_id) { + removedImages.push(image_id); +} + +// Update the hidden input with the updated array as JSON string +imagesToRemove.val(JSON.stringify(removedImages)); + +// Remove the image element from the DOM +$(this).parent('.edit_wrapper-thumb').remove(); + + // Ask for confirmation + if (confirm("Are you sure you want to delete this image?")) { + $.ajaxSetup({ + headers: { + "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), + } + }); + + $.ajax({ + type: "DELETE", + dataType: "json", + url: "{{route('delete_image')}}", + data: { + image_id: image_id, + image_path: image_path, + }, + success: function (response) { + if (response.status == 200) { + toastr.success('Image Deleted Successfully'); + setTimeout(function () { + // Redirect or perform any other action after successful deletion. + // window.location.href = url_path + "/programe_edit"; + }, 1000); + } else { + toastr.error("Something went wrong"); + } + }, + }); + } +}); + @endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 852e46a..86ffbeb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -612,8 +612,9 @@ Route::middleware([BackendAccess::class])->group(function () { Route::post("monthly-updates-change-status", 'monthlyUpdateChangeStatus')->name('monthly-updates-change-status'); Route::post("redeem-with-sold-amount",'redeemWithSoldAmount')->name('redeem-with-sold-amount'); }); - + //Manage FreeU Investments + Route::delete('delete_image', [VentureCapitalFundController::class, 'delete_image'])->name('delete_image'); Route::prefix('manage-investments')->group(function () { Route::controller(ManageFreeUInvestmentController::class)->as('manage.')->group(function () { Route::get("/products", 'index')->name('products'); @@ -622,6 +623,7 @@ Route::middleware([BackendAccess::class])->group(function () { Route::get("/fractional-real-estate/upload", 'addProduct')->name('addproduct'); Route::post("/product/post", 'uploadFile')->name('postproduct'); Route::delete("/product/delete", 'productDelete')->name('product-delete'); + //Bonds Route::prefix('bonds/upload/')->group(function () {