Current File : /home/tradevaly/new.tradevaly.com.bd/app/Http/Controllers/Admin/FeaturesController.php
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Product;
use App\Models\Category;
use App\Models\FeaturedCategory;
use App\Models\FeaturedProduct;
use App\Models\FeaturedRequest;
use Brian2694\Toastr\Facades\Toastr;
use Illuminate\Http\Request;
use DataTables;
class FeaturesController extends Controller
{
    public function index(Request $request){
        $data['products'] = FeaturedProduct::where('status', 1)->latest()->paginate(20);
        //  if ($request->ajax()) {
        //     $data = FeaturedProduct::where('status', 1)->get();
        //     return Datatables::of($data)
        //         ->addIndexColumn()
        //         ->addColumn('action', function($row){
        //             $actionBtn = '<a  onclick="return confirm(\'Are you sure?\')" href="'.url('b2b/feature_product/delete',$row->id).'" class="text-danger confirmDelete"><i class="fas fa-trash fa-lg"></i></a>';
        //             return $actionBtn;
        //         })
        //         ->addColumn('name', function($row){
        //             return $row->product->title;
        //         })
        //         ->addColumn('des', function($row){
        //             return \Illuminate\Support\Str::limit(strip_tags($row->product->details), 70, $end='...');
        //         })
        //         ->addColumn('supplier', function($row){
        //             if(isset($row->product->supplier->name)){ 
        //             return $row->product->supplier->name;
        //             }
        //         })
        //         ->addColumn('package', function($row){
                    
        //              if(isset($row->product->supplier->user->package->image)){ 
        //             return '<img src="'.asset('storage/images/admin/package/'.$row->product->supplier->user->package->image).'" alt="Service Image" class="mt-2" height="40px">';
        //             }
        //         })
        //          ->rawColumns(['action', 'des', 'package'])
        //         ->make(true);
        // }
        return view('backend.pages.featureProduct.index')->with($data);
    }
    
    public function pending(){
        $Fproducts= FeaturedRequest::all();
        return view('backend.pages.featureProduct.pending')->with(compact('Fproducts'));
    }
    
    
    public function add(Request $request){
        if($request->isMethod("post")){
             $data= new FeaturedProduct;
             $data->product_id=$request->product_id;
             $data->status=1;
             $data->save();
             Toastr::success('Success!','Feature uploaded!');
             return redirect()->back();
        }
       
    }
    public function featureRequest(Request $request){
        if($request->isMethod("post")){
             $data= new FeaturedProduct;
             $data->product_id=$request->product_id;
             $data->status=1;
             $data->save();
             Toastr::success('Success!','Feature uploaded!');
             return redirect()->back();
        }
        // return view ("")
       
    }

    public function delete($id){
            $work=FeaturedProduct::find($id);
            $work->delete();
            Toastr::success('Success!','Feature deleted!');
            return redirect()->back();
    }
    public function featur_request_delete($id){
            $work=FeaturedRequest::find($id);
            $work->delete();
            Toastr::success('Success!','Feature deleted!');
            return redirect()->back();
    }
    public function cindex(){
        $categories= Category::all();
        $pros= FeaturedCategory::all();
        return view('backend.pages.featureProduct.cindex')->with(compact('pros','categories'));
    }
    public function cadd(Request $request){
        if($request->isMethod("post")){
             $data= new FeaturedCategory;
             $data->category_id=$request->category_id;
             $data->status=1;
             $data->save();
             Toastr::success('Success!','Feature uploaded!');
             return redirect()->back();
        }
       
    }

    public function cdelete($id){
            $work=FeaturedCategory::find($id);
            $work->delete();
            Toastr::success('Success!','Feature deleted!');
            return redirect()->back();
    }
    
    public function delreq($id){
        $prodt = FeaturedRequest::findorFail($id);
        
             $prodt->delete();
         Toastr::success('Success!','Feature deleted!');
        return redirect()->back();
         
    }
    
    public function approve($id){
        $prodt = FeaturedRequest::findorFail($id);
        $data = new FeaturedProduct();
        $data->product_id=$prodt->product_id;
        $data->user_id=$prodt->user_id;
         $data->status=1;
         if($data->save()){
             $prodt->delete();
         Toastr::success('Success!','Feature Approved!');
        return redirect()->back();
         }
    }
    
}