diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 0d368c8..474996c 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -20,9 +20,20 @@ class CategoryController extends Controller */ public function index(Request $request) { + // Obtenemos valor de input de búsqueda + $inputSearchValue = trim($request->get("searchCategory")); + + $categories = Category::paginate(); + + return view('Admin.category.index', compact('categories', "inputSearchValue")) + ->with('i', (request()->input('page', 1) - 1) * $categories->perPage()); + } + // Función para buscar categorías + public function search(Request $request) + { // Obtenemos valor de input de búsqueda - $inputSearchValue = trim($request->get("categorieSearch")); + $inputSearchValue = trim($request->get("searchCategory")); // Autoincrementable para Columna No de vista $a = 0; @@ -30,11 +41,11 @@ public function index(Request $request) // Realiza las consultas a las tablas junto con la tabla categorías $categories = DB::table("categories") - ->select("id", "name", "description") - ->where("name", "LIKE", "%" . $inputSearchValue . "%") - ->orWhere("id", "LIKE", "%" . $inputSearchValue . "%") - ->orderBy("name", "asc") - ->paginate(10); + ->select("id", "name", "description") + ->where("name", "LIKE", "%" . $inputSearchValue . "%") + ->orWhere("id", "LIKE", "%" . $inputSearchValue . "%") + ->orderBy("name", "asc") + ->paginate(10); return view('Admin.category.index', compact("categories", "i", "inputSearchValue")); } @@ -71,12 +82,12 @@ public function store(Request $request) * @param int $id * @return \Illuminate\Http\Response */ - public function show($id) - { - $category = Category::find($id); + // public function show($id) + // { + // $category = Category::find($id); - return view('Admin.category.show', compact('category')); - } + // return view('Admin.category.index', compact('category')); + // } /** * Show the form for editing the specified resource. diff --git a/resources/views/Admin/category/index.blade.php b/resources/views/Admin/category/index.blade.php index 5f30231..7208578 100644 --- a/resources/views/Admin/category/index.blade.php +++ b/resources/views/Admin/category/index.blade.php @@ -26,8 +26,8 @@ -
diff --git a/resources/views/Admin/category/show.blade.php b/resources/views/Admin/category/show.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/routes/web.php b/routes/web.php index 8cbce02..6360a4c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -33,7 +33,10 @@ Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home'); // Ruta Categorías Productos -Route::resource('products/categories', CategoryController::class)->middleware("auth"); +Route::resource('products/categories', CategoryController::class)->middleware("auth")->except(['show']); + + // Ruta para buscar Categorías de productos + Route::get('products/categories/search', [CategoryController::class, 'search'])->name('categories.search'); // Ruta Productos Route::resource('products', ProductController::class)->middleware("auth"); diff --git a/tests/Feature/CategoryTest.php b/tests/Feature/CategoryTest.php new file mode 100644 index 0000000..d61c048 --- /dev/null +++ b/tests/Feature/CategoryTest.php @@ -0,0 +1,40 @@ + "Categoría ejemplo 1", + // "description" => "Descripción Categoria ejemplo 1" + // ]; + + // $response = $this->post("products/categories", $category); + + // $response->assertStatus(302); + // $response->assertRedirect(route("categories.index")); + + // $this->assertDatabaseCount("categories", 3); + + // $lastCategoryCreated = Category::query()->latest()->first(); + + // $this->assertDatabaseHas("categories", [ + // "name" => $lastCategoryCreated->name, + // "description" => $lastCategoryCreated->description, + // ]); + + // $this->assertDatabaseHas("categories", $category); + + // $this->assertEquals($category["name"], $lastCategoryCreated->name); + // $this->assertEquals($category["description"], $lastCategoryCreated->description); + // } +} diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index 0914ede..8364a84 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -16,9 +16,4 @@ public function test_the_application_returns_a_successful_response(): void $response->assertStatus(200); } - - public function test_basic_test(): void - { - $this->assertTrue(true); - } } diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index 5773b0c..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,16 +0,0 @@ -assertTrue(true); - } -}