Skip to content

Commit

Permalink
Creación buscador Categorías de productos
Browse files Browse the repository at this point in the history
  • Loading branch information
FazeElian committed Dec 4, 2023
1 parent 00776c1 commit c09ff84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
25 changes: 20 additions & 5 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; // Para consultas desde tablas para buscador

/**
* Class CategoryController
Expand All @@ -14,14 +15,28 @@ class CategoryController extends Controller
/**
* Display a listing of the resource.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function index()
public function index(Request $request)
{
$categories = Category::paginate();

return view('Admin.category.index', compact('categories'))
->with('i', (request()->input('page', 1) - 1) * $categories->perPage());
// Obtenemos valor de input de búsqueda
$inputSearchValue = trim($request->get("categorieSearch"));

// Autoincrementable para Columna No de vista
$a = 0;
$i = $a++;

// 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);

return view('Admin.category.index', compact("categories", "i", "inputSearchValue"));
}

/**
Expand Down Expand Up @@ -73,7 +88,7 @@ public function edit($id)
{
$category = Category::find($id);

return view('Aqdmin.category.edit', compact('category'));
return view('Admin.category.edit', compact('category'));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions resources/views/Admin/category/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
</div>

<!-- Barra de búsqueda -->
<div class="cont-barra-busqueda">
<input type="search" name="barraBusquedaCategorias" id="barraBusqueda" placeholder=" Buscar categoría de productos">
</div>
<form action="{{ route("categories.index") }}" method="get" class="cont-barra-busqueda">
<input type="search" name="categorieSearch" id="barraBusqueda" placeholder="Buscar categoría de productos" value="{{ $inputSearchValue }}">
</form>

<!-- Tabla categorías -->
<table class="tabla-categorias" id="tabla-categorias">
Expand Down

0 comments on commit c09ff84

Please sign in to comment.