CategoryController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace App\Http\Controllers\Backend;
  3. use App\Repositories\CategoryRepositoryEloquent;
  4. use Illuminate\Http\Request;
  5. use App\Http\Requests;
  6. use App\Http\Controllers\Controller;
  7. use App\Models\Category;
  8. use App\Http\Requests\Backend\Category\CreateRequest;
  9. use App\Http\Requests\Backend\Category\UpdateRequest;
  10. class CategoryController extends Controller
  11. {
  12. protected $category;
  13. public function __construct(CategoryRepositoryEloquent $category)
  14. {
  15. $this->category = $category;
  16. }
  17. /**
  18. * Display a listing of the resource.
  19. *
  20. * @return \Illuminate\Http\Response
  21. */
  22. public function index()
  23. {
  24. /*$root = Category::create(['name' => 'Root category2']);
  25. $child1 = $root->children()->create(['name' => 'Child 1']);
  26. // with the `makeChildOf` method
  27. $child2 = Category::create(['name' => 'Child 2']);
  28. $child2->makeChildOf($root);
  29. exit();*/
  30. $category = $this->category->getNestedList();
  31. return view("backend.category.index", compact('category'));
  32. }
  33. /**
  34. * Show the form for creating a new resource.
  35. *
  36. * @return \Illuminate\Http\Response
  37. */
  38. public function create()
  39. {
  40. return view('backend.category.create');
  41. }
  42. /**
  43. * Store a newly created resource in storage.
  44. *
  45. * @param \Illuminate\Http\Request $request
  46. * @return \Illuminate\Http\Response
  47. */
  48. public function store(CreateRequest $request)
  49. {
  50. dd($request);
  51. }
  52. /**
  53. * Display the specified resource.
  54. *
  55. * @param int $id
  56. * @return \Illuminate\Http\Response
  57. */
  58. public function show($id)
  59. {
  60. //
  61. }
  62. /**
  63. * Show the form for editing the specified resource.
  64. *
  65. * @param int $id
  66. * @return \Illuminate\Http\Response
  67. */
  68. public function edit($id)
  69. {
  70. $category = $this->category->find($id);
  71. return view('backend.category.edit', compact('category'));
  72. }
  73. /**
  74. * Update the specified resource in storage.
  75. *
  76. * @param \Illuminate\Http\Request $request
  77. * @param int $id
  78. * @return \Illuminate\Http\Response
  79. */
  80. public function update(UpdateRequest $request, $id)
  81. {
  82. //
  83. }
  84. /**
  85. * Remove the specified resource from storage.
  86. *
  87. * @param int $id
  88. * @return \Illuminate\Http\Response
  89. */
  90. public function destroy($id)
  91. {
  92. $category = Category::find($id);
  93. if ($category) {
  94. if ($category->delete()) {
  95. return response()->json(['status' => 0]);
  96. }
  97. }
  98. return response()->json(['status' => 1]);
  99. }
  100. }