ProductBulkUploadController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Category;
  5. use App\Models\Brand;
  6. use App\Models\User;
  7. use App\Models\ProductsImport;
  8. use App\Models\ProductsExport;
  9. use PDF;
  10. use Excel;
  11. use Auth;
  12. class ProductBulkUploadController extends Controller
  13. {
  14. public function index()
  15. {
  16. if (Auth::user()->user_type == 'seller') {
  17. if(Auth::user()->shop->verification_status){
  18. return view('seller.product_bulk_upload.index');
  19. }
  20. else{
  21. flash('Your shop is not verified yet!')->warning();
  22. return back();
  23. }
  24. }
  25. elseif (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
  26. return view('backend.product.bulk_upload.index');
  27. }
  28. }
  29. public function export(){
  30. return Excel::download(new ProductsExport, 'products.xlsx');
  31. }
  32. public function pdf_download_category()
  33. {
  34. $categories = Category::all();
  35. return PDF::loadView('backend.downloads.category',[
  36. 'categories' => $categories,
  37. ], [], [])->download('category.pdf');
  38. }
  39. public function pdf_download_brand()
  40. {
  41. $brands = Brand::all();
  42. return PDF::loadView('backend.downloads.brand',[
  43. 'brands' => $brands,
  44. ], [], [])->download('brands.pdf');
  45. }
  46. public function pdf_download_seller()
  47. {
  48. $users = User::where('user_type','seller')->get();
  49. return PDF::loadView('backend.downloads.user',[
  50. 'users' => $users,
  51. ], [], [])->download('user.pdf');
  52. }
  53. public function bulk_upload(Request $request)
  54. {
  55. if($request->hasFile('bulk_file')){
  56. $import = new ProductsImport;
  57. Excel::import($import, request()->file('bulk_file'));
  58. }
  59. return back();
  60. }
  61. }