Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. <?php
  2.  
  3. namespace app\http\controllers;
  4.  
  5. class guv6s5j3k5kyhomu19x3q37 extends Controller
  6. {
  7. public function listCategory()
  8. {
  9. $categorys = App\category_files::where('parent_id', '0')->orwhere('parent_id', null)->orderBy('created_at', 'asc')->paginate(3);
  10.  
  11. foreach ($categorys as $category) {
  12. $subCategorys[$category->id] = App\category_files::where('parent_id', $category->id)->orderBy('created_at', 'asc')->get()->all();
  13.  
  14. foreach ($subCategorys[$category->id] as $subCategory) {
  15. $subCategorys2[$subCategory->id] = App\category_files::where('parent_id', $subCategory->id)->orderBy('created_at', 'asc')->get()->all();
  16. }
  17. }
  18.  
  19. $PostCategorys = App\category_files::orderBy('created_at', 'asc')->get()->all();
  20.  
  21. foreach ($PostCategorys as $PostCategory) {
  22. $countPostCategory[$PostCategory->id] = $PostCategory->files()->count();
  23. }
  24.  
  25. return view($this->theme_admin() . '.dash')->nest('content', $this->theme_admin() . '.categorys.list', compact('categorys', 'subCategorys', 'subCategorys2', 'countPostCategory'))->with('title', 'دسته بندی ها');
  26. }
  27.  
  28. public function newCategory()
  29. {
  30. $categorys = App\category_files::where('parent_id', '0')->orwhere('parent_id', null)->orderBy('created_at', 'asc')->get()->all();
  31. $parentCategorys[0] = 'بدون والد';
  32. $subCategorys[0] = array();
  33.  
  34. foreach ($categorys as $category) {
  35. $parentCategorys[$category->id] = $category->name;
  36. $subCategorys[$category->id] = App\category_files::where('parent_id', $category->id)->orderBy('created_at', 'asc')->get()->all();
  37. }
  38.  
  39. $pro_categorys = App\category_products::where('parent_id', '0')->orwhere('parent_id', null)->orderBy('created_at', 'asc')->get()->all();
  40.  
  41. foreach ($pro_categorys as $pro_category) {
  42. $pro_subCategorys[$pro_category->id] = App\category_products::where('parent_id', $pro_category->id)->orderBy('created_at', 'asc')->get()->all();
  43.  
  44. foreach ($pro_subCategorys[$pro_category->id] as $pro_subCategory) {
  45. $pro_subCategorys2[$pro_subCategory->id] = App\category_products::where('parent_id', $pro_subCategory->id)->orderBy('created_at', 'asc')->get()->all();
  46. }
  47. }
  48.  
  49. return view($this->theme_admin() . '.dash')->nest('content', $this->theme_admin() . '.categorys.new', compact('parentCategorys', 'subCategorys', 'pro_categorys', 'pro_subCategorys', 'pro_subCategorys2'))->with('title', 'اضافه کردن دسته بندی');
  50. }
  51.  
  52. public function saveCategory(Illuminate\Http\Request $Request)
  53. {
  54. if ($Request->hasFile('img_blank')) {
  55. $allFiles = $Request->file('img_blank');
  56.  
  57. if (!$this->validateFile($allFiles)) {
  58. return redirect()->back()->with('error', 'خطا: فقط تصاویر مجاز به آپلود می باشند.');
  59. }
  60. }
  61.  
  62. $this->validate($Request, array('name' => 'required|min:3|unique:category_files,name', 'parent_id' => 'integer'));
  63.  
  64. if (count($Request['cat_product_ids']) == 0) {
  65. $Request['cat_product_ids'] = array();
  66. }
  67.  
  68. $posts = App\category_files::create(array('parent_id' => $Request['parent_id'], 'name' => $Request['name'], 'content' => $Request['content'], 'cat_product_ids' => json_encode($Request['cat_product_ids']), 'demo' => $Request['demo'], 'status' => $Request['status'], 'index_view' => $Request['index_view']));
  69. $imageArray = array();
  70.  
  71. if (isset($allFiles)) {
  72. ..........................................................
  73. ......................
  74. .........
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement