Current File : /home/tradevaly/new.tradevaly.com.bd/app/Http/Controllers/Admin/AboutController.php |
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\About;
use App\Models\Income;
use App\Models\User;
use App\Models\Company;
use App\Models\AdvertiserOrder;
use App\Models\Logo;
use App\Models\BuyOffer;
use App\Models\GeneralInfo;
use App\Models\Product;
use Brian2694\Toastr\Facades\Toastr;
use Illuminate\Http\Request;
use App\Models\Tag;
use App\Models\Category;
use App\Models\Method;
use Carbon\Carbon;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Auth;
use Str;
class AboutController extends Controller
{
public function index(){
$abouts= About::latest()->get();
return view('backend.pages.about.index')->with(compact('abouts'));
}
public function income(){
$incomes= Income::latest()->get();
return view('backend.pages.category.income')->with(compact('incomes'));
}
public function IncomeInvoiceDetails($id)
{
$invoice = Income::with('user:id,name,industry,email,package_id,type,address,products,country_id','package')->where('id', $id)->firstOrFail();
return view('backend.pages.category.invoice',compact('invoice'));
}
public function IncomeMoneyReceipt($id)
{
$money_receipt = Income::where('id', $id)->firstOrFail();
return view('backend.pages.category.money_receipt',compact('money_receipt'));
}
public function updateAboutStatus(Request $request){
if($request->ajax()){
$data=$request->all();
if($data['status']=='Active'){
$status=0;
}else{
$status=1;
}
About::where('id',$data['about_id'])->update(['status'=>$status]);
return response()->json(['status'=>$status, 'about_id'=>$data['about_id']]);
}
}
public function add(Request $request){
if($request->isMethod("post")){
$data= new about;
$data->title=$request->title;
$data->link=$request->link;
$data->details=$request->details;
$data->status=1;
$data->save();
Toastr::success('Success!','About uploaded!');
return redirect()->back();
}
return view('backend.pages.about.add');
}
public function breject($id){
$work=BuyOffer::find($id);
$work->delete();
Toastr::success('Success!','Offer deleted!');
return redirect()->back();
}
public function bapprove($id){
$work=BuyOffer::find($id);
$work->status = 1;
$work->save();
Toastr::success('Success!','Offer Approved!');
return redirect()->back();
}
public function delete($id){
$work=about::find($id);
$work->delete();
Toastr::success('Success!','about deleted!');
return redirect()->back();
}
public function edit(Request $request, $id){
$data=about::find($id);
if($request->isMethod("post")){
$data->title=$request->title;
$data->link=$request->link;
$data->details=$request->details;
$data->status=1;
$data->save();
Toastr::success('Success!','about Updated!');
return redirect()->back();
}
$categories= about::all();
return view('backend.pages.about.edit')->with(compact('categories','data'));
}
public function buy_offer($id=0){
if($id != 0){
$offers = BuyOffer::where('status',1)->where('buyer_id', $id)->paginate(50);
} else {
$offers = BuyOffer::where('status',1)->paginate(50);
}
return view('backend.pages.users.buy_offer',compact("offers"));
}
public function bpending(){
$offers = BuyOffer::where('status',0)->paginate(50);
return view('backend.pages.users.buy_offer',compact("offers"));
}
public function product_list($id=0){
if($id != 0){
$products = Product::where('status',1)->where('supplier_id', $id)->get();
} else {
$products = Product::where('status',1)->get();
}
return view('backend.pages.users.product_list',compact("products"));
}
public function pdelete($id){
$product = Product::find($id);
if($product->status == '0'){
$product->status = 3;
$product->save();
}
Toastr::error('Success!','Product Rejected Successfully!');
return redirect()->route('admin.product_list.product_list');
}
public function approve($id){
Product::where('id',$id)->update(['status'=>1]);
return redirect()->back();
}
public function uapprove ($id){
User::where('id',$id)->update(['status'=>1]);
return redirect()->back();
}
public function pending(){
$products = Product::where('status',0)->paginate(50);
return view('backend.pages.users.product_list',compact("products"));
}
public function udelete($id){
$product = User::find($id)->delete();
return redirect()->route('admin.users.all');
}
public function addUser(){
return view('backend.pages.users.add');
}
public function addProduct(Request $request){
if($request->isMethod("post")){
$product=new Product();
if($request->hasFile('image'))
{
$image=$request->file('image');
$currentDate=Carbon::now()->toDateString();
$imageName=$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
if(!Storage::disk('public')->exists('images/admin/product/'.$product->image))
{
Storage::disk('public')->makeDirectory('images/admin/product/'.$product->image);
}
$bannerImage = Image::make($image)->resize(500,500)->stream();
Storage::disk('public')->put('images/admin/product/'.$imageName,$bannerImage);
$product->image=$imageName;
}else{
$imageName= "product.jpg";
}
if($request->hasFile('gallary1'))
{
$image=$request->file('gallary1');
$currentDate=Carbon::now()->toDateString();
$imageName=$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
if(!Storage::disk('public')->exists('images/admin/product/'.$product->gallary1))
{
Storage::disk('public')->makeDirectory('images/admin/product/'.$product->gallary1);
}
$bannerImage = Image::make($image)->resize(500,500)->stream();
Storage::disk('public')->put('images/admin/product/'.$imageName,$bannerImage);
$product->gallary1=$imageName;
}else{
$imageName= "product.jpg";
}
if($request->hasFile('gallary2'))
{
$image=$request->file('gallary2');
$currentDate=Carbon::now()->toDateString();
$imageName=$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
if(!Storage::disk('public')->exists('images/admin/product/'.$product->gallary2))
{
Storage::disk('public')->makeDirectory('images/admin/product/'.$product->gallary2);
}
$bannerImage = Image::make($image)->resize(500,500)->stream();
Storage::disk('public')->put('images/admin/product/'.$imageName,$bannerImage);
$product->gallary2=$imageName;
}else{
$imageName= "product.jpg";
}
if($request->hasFile('gallary3'))
{
$image=$request->file('gallary3');
$currentDate=Carbon::now()->toDateString();
$imageName=$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
if(!Storage::disk('public')->exists('images/admin/product/'.$product->gallary3))
{
Storage::disk('public')->makeDirectory('images/admin/product/'.$product->gallary3);
}
$bannerImage = Image::make($image)->resize(500,500)->stream();
Storage::disk('public')->put('images/admin/product/'.$imageName,$bannerImage);
$product->gallary3=$imageName;
}else{
$imageName= "product.jpg";
}
if($request->hasFile('gallary4'))
{
$image=$request->file('gallary4');
$currentDate=Carbon::now()->toDateString();
$imageName=$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
if(!Storage::disk('public')->exists('images/admin/product/'.$product->gallary4))
{
Storage::disk('public')->makeDirectory('images/admin/product/'.$product->gallary4);
}
$bannerImage = Image::make($image)->resize(500,500)->stream();
Storage::disk('public')->put('images/admin/product/'.$imageName,$bannerImage);
$product->gallary4=$imageName;
}else{
$imageName= "product.jpg";
}
$product->ip = visitorip();
$product->title = $request->title;
$product->date = date('Y-m-d');
$product->slug=Str::slug($request->title);
$product->details = $request->des;
$product->country_id = Auth::guard("admin")->user()->country_id;
if($request->filled('child_id')){
$product->category_id = $request->child_id;
$product->sub_id = $request->sub_id;
$product->child_id = $request->category_id;
} else {
$product->category_id = $request->sub_id;
$product->sub_id = $request->category_id;
}
$product->tags = json_encode($request->tags);
$product->video = $request->video;
$product->processing_time = $request->processing_time;
$product->port = $request->port;
$product->unit = $request->unit;
$product->supply_ability = $request->supply_ability;
$product->payment_method = $request->payment_method;
$product->origin = $request->origin;
$product->location = $request->location;
$product->currency = $request->currency;
$product->stock = $request->stock;
$product->location = $request->location;
$product->supplier_id = $request->supplier_id;
if($product->save()){
Toastr::success('Success!','Setting Updated!');
return redirect()->back();
}
}
$data['tags'] = Tag::all();
$data['caegories'] = Category::where('parent_id', 0)->get();
$data['method'] = Method::all();
return view('backend.pages.users.addproducts')->with($data);
}
public function uploadLogo(Request $request){
$data= Logo::first();
if($request->isMethod('post')){
$request->validate([
'email'=> 'required',
'number'=> 'required',
]);
if($request->hasFile('image'))
{
$image=$request->file('image');
$currentDate=Carbon::now()->toDateString();
$imageName=$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
if(!Storage::disk('public')->exists('images/admin/logo'))
{
Storage::disk('public')->makeDirectory('images/admin/logo');
}
$bannerImage = Image::make($image)->resize(275,80)->stream();
Storage::disk('public')->put('images/admin/logo/'.$imageName,$bannerImage);
$data->image=$imageName;
}
$data->email = $request->email;
$data->number = $request->number;
$data->address = $request->address;
$data->whatsapp_number = $request->whatsapp_number;
$data->facbook = $request->facbook;
$data->twitter = $request->twitter;
$data->linkdin = $request->linkdin;
$data->youtube = $request->youtube;
$data->instagram = $request->instagram;
$data->meta_author = $request->meta_author;
$data->meta_title = $request->meta_title;
$data->meta_description = $request->meta_description;
$data->meta_tages = $request->meta_tages;
$data->copyright = $request->copyright;
$data->surjopay_username = $request->surjopay_username;
$data->surjopay_passwrod = $request->surjopay_passwrod;
$this->pushIntoEnv('MERCHANT_USERNAME',$request->surjopay_username);
$this->pushIntoEnv('MERCHANT_PASSWORD',$request->surjopay_passwrod);
$data->update();
Toastr::success('Success!','Logo Updated!');
return redirect()->back();
}
return view('backend.pages.users.upload_logo',compact('data'));
}
public function advertiser_banner(Request $request){
$data= Logo::first();
$categories = Category::where('parent_id' , 0)->latest()->get();
if($request->isMethod('post')){
$data->top_banner = $request->top_banner;
$data->classic_banner = $request->classic_banner;
$data->bottom_banner = $request->bottom_banner;
$data->top_category_banner = $request->top_category_banner;
$data->bottom_category_banner = $request->bottom_category_banner;
$data->top_buyer_banner = $request->top_buyer_banner;
$data->bottom_buyer_banner = $request->bottom_buyer_banner;
$data->top_company_banner = $request->top_company_banner;
$data->bottom_company_banner = $request->bottom_company_banner;
$data->top_product_banner = $request->top_product_banner;
$data->bottom_product_banner = $request->bottom_product_banner;
$data->top_manufacture_banner = $request->top_manufacture_banner;
$data->bottom_manufacture_banner = $request->bottom_manufacture_banner;
$data->top_banner_discount = $request->top_banner_discount;
$data->classic_banner_discount = $request->classic_banner_discount;
$data->bottom_banner_discount = $request->bottom_banner_discount;
$data->top_buyer_banner_discount = $request->top_buyer_banner_discount;
$data->bottom_buyer_banner_discount = $request->bottom_buyer_banner_discount;
$data->top_product_banner_discount = $request->top_product_banner_discount;
$data->bottom_product_banner_discount = $request->bottom_product_banner_discount;
$data->top_company_banner_discount = $request->top_company_banner_discount;
$data->bottom_company_banner_discount = $request->bottom_company_banner_discount;
$data->top_manufacture_banner_discount = $request->top_manufacture_banner_discount;
$data->bottom_manufacture_banner_discount = $request->bottom_manufacture_banner_discount;
$data->contact_banner_discount = $request->contact_banner_discount;
$data->top_category_banner_discount = $request->top_category_banner_discount;
$data->bottom_category_banner_discount = $request->bottom_category_banner_discount;
$data->contact_banner = $request->contact_banner;
$data->update();
Toastr::success('Success!','Information Updated Successfully!');
return back();
}
return view('backend.pages.users.advertiser',compact('data'));
}
public function advertiser(){
$data['advertisers'] = AdvertiserOrder::where('status','active')->whereNotNull('start_date')->latest()->get();
return view('backend.pages.advertiser.index')->with($data);
}
public function pending_advertiser(){
$data['advertisers'] = AdvertiserOrder::latest()->get();
return view('backend.pages.advertiser.pending')->with($data);
}
public function others_advertiser(){
$data['advertisers'] = AdvertiserOrder::latest()->get();
return view('backend.pages.advertiser.pending')->with($data);
}
public function status(Request $request, $id){
$advertiser = AdvertiserOrder::findOrFail($id);
if($advertiser->status == 'active'){
$advertiser->status = 'unactive';
}else{
$advertiser->status = 'active';
}
$advertiser->start_date = $request->start_date;
$advertiser->expire_date = $request->expire_date;
$advertiser->status = 'active';
$advertiser->save();
Toastr::success('Success!','Advertiser Status Updated Successfully!');
return back();
}
public function unactive_status($id){
$advertiser = AdvertiserOrder::findOrFail($id);
$advertiser->status = 'unactive';
$advertiser->save();
Toastr::error('Success!','Advertiser Status Updated Successfully!');
return back();
}
public function pushIntoEnv($key, $value)
{
$path = base_path('.env');
if (file_exists($path)) {
$lines = explode("\n", file_get_contents($path));
$settings = collect($lines)
->filter()
->transform(function ($item) {
return explode("=", $item, 2);
})->pluck(1, 0);
$settings[$key] = $value;
$rebuilt = $settings->map(function ($value, $key) {
return "$key=$value";
})->implode("\n");
file_put_contents($path, $rebuilt);
}
}
public function destroy_advertiser($id){
$advertiser = AdvertiserOrder::findOrFail($id);
$advertiser->delete();
Toastr::success('Success!','Advertiser Order Deleted Successfully!');
return back();
}
public function show_advertiser($id){
$invoice = AdvertiserOrder::with('user:id,name,industry,email,package_id,type,address,products,country_id')->where('id', $id)->firstOrFail();
return view('backend.pages.advertiser.invoice',compact('invoice'));
}
public function advertiserInvoiceDetails($id)
{
$invoice = AdvertiserOrder::with('user:id,name,industry,email,package_id,type,address,products,country_id')->where('id', $id)->firstOrFail();
return view('backend.pages.advertiser.invoice',compact('invoice'));
}
public function advertiserMoneyReceipt($id)
{
$money_receipt = AdvertiserOrder::where('id', $id)->firstOrFail();
return view('backend.pages.advertiser.money_receipt',compact('money_receipt'));
}
}