Files
BUT2/mini-crm/resources/views/products/index.blade.php
T

49 lines
1.8 KiB
PHP

@extends('layouts.app')
@section('content')
<h2>Liste des produits</h2>
{{-- TP3 : affichage des produits ; TP4 : actions CRUD et indication de stock faible. --}}
<p>Nombre total de produits : {{ $products->total() }}</p>
<p><a href="{{ route('products.create') }}">Ajouter un produit</a></p>
{{-- TP6 : recherche par nom ; le prix est inclus pour le bonus. --}}
<form method="GET" action="{{ route('products.index') }}">
<label for="product-search">Rechercher par nom ou prix</label>
<input id="product-search" type="search" name="search" value="{{ $search }}" placeholder="Rechercher un produit">
<button type="submit">Rechercher</button>
<a href="{{ route('products.index') }}">Effacer</a>
</form>
<table>
<tr>
<th>Produit</th>
<th>Prix</th>
<th>Stock</th>
<th>Disponibilité</th>
<th>Actions</th>
</tr>
@foreach($products as $produit)
<tr>
<td>{{ $produit->name }}</td>
<td>{{ $produit->price }} €</td>
<td>{{ $produit->stock }}</td>
<td>
@if($produit->stock < 5)
⚠ Stock faible
@else
Stock disponible
@endif
</td>
<td>
<a href="{{ route('products.show', $produit) }}">Voir</a>
<a href="{{ route('products.edit', $produit) }}">Modifier</a>
<form method="POST" action="{{ route('products.destroy', $produit) }}" style="display: inline">
@csrf
@method('DELETE')
<button type="submit">Supprimer</button>
</form>
</td>
</tr>
@endforeach
</table>
{{-- TP6 : la recherche est conservée dans les liens grâce à withQueryString(). --}}
{{ $products->links() }}
@endsection