Skip to content

Commit

Permalink
Creación de buscador para Productos
Browse files Browse the repository at this point in the history
  • Loading branch information
FazeElian committed Dec 4, 2023
1 parent 757d587 commit 00776c1
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/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Models\Product;
use App\Models\Category;
use Illuminate\Http\Request;

use Illuminate\Support\Facades\DB;
// Guardar Imagen en el storage
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Storage;
Expand All @@ -20,13 +20,28 @@ class ProductController extends Controller
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
* @param \Illuminate\Http\Request $request
*/
public function index()
public function index(Request $request)
{
$products = Product::paginate();
// Obtenemos valor de input de búsqueda
$inputSearchValue = trim($request->get("productSearch"));

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

// Realiza las consultas a las tablas junto con la tabla categorías
$products = Product::with('category')
->select("id", "name", "categorie_id")
->where("name", "LIKE", "%" . $inputSearchValue . "%")
->orWhere("categorie_id", "LIKE", "%" . $inputSearchValue . "%")
->orderBy("name", "asc")
->paginate(10);

$categories = Category::select("id", "name")->get();

return view('Admin.product.index', compact('products'))
->with('i', (request()->input('page', 1) - 1) * $products->perPage());
return view('Admin.product.index', compact("products", "categories" ,"inputSearchValue", "i"));
}

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

<div class="barra_busqueda">
<input type="search" name="barra_busqueda" id="barra_busqueda" placeholder="Buscar Producto">
</div>
<form action="{{ route("products.index") }}" method="get" class="barra_busqueda">
<input type="search" name="productSearch" id="barra_busqueda" placeholder="Buscar Producto" value="{{ $inputSearchValue }}" class="barra_busqueda">
</form>
</div>

{{-- Sección de lista de productos --}}
Expand Down

0 comments on commit 00776c1

Please sign in to comment.