2026-09-16 11:43:27 +02:00
|
|
|
@extends('layouts.app')
|
|
|
|
|
@section('content')
|
2026-10-07 00:48:56 +02:00
|
|
|
<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>
|
2026-09-16 11:43:27 +02:00
|
|
|
<table>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>Produit</th>
|
|
|
|
|
<th>Prix</th>
|
|
|
|
|
<th>Stock</th>
|
2026-10-07 00:48:56 +02:00
|
|
|
<th>Disponibilité</th>
|
|
|
|
|
<th>Actions</th>
|
2026-09-16 11:43:27 +02:00
|
|
|
</tr>
|
|
|
|
|
@foreach($products as $produit)
|
|
|
|
|
<tr>
|
2026-10-07 00:48:56 +02:00
|
|
|
<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>
|
2026-10-21 00:48:38 +02:00
|
|
|
@can('update', $produit)
|
|
|
|
|
<a href="{{ route('products.edit', $produit) }}">Modifier</a>
|
|
|
|
|
@endcan
|
|
|
|
|
@can('delete', $produit)
|
2026-10-07 00:48:56 +02:00
|
|
|
<form method="POST" action="{{ route('products.destroy', $produit) }}" style="display: inline">
|
|
|
|
|
@csrf
|
|
|
|
|
@method('DELETE')
|
|
|
|
|
<button type="submit">Supprimer</button>
|
|
|
|
|
</form>
|
2026-10-21 00:48:38 +02:00
|
|
|
@endcan
|
2026-09-16 11:43:27 +02:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
@endforeach
|
|
|
|
|
</table>
|
2026-10-07 00:48:56 +02:00
|
|
|
{{-- TP6 : la recherche est conservée dans les liens grâce à withQueryString(). --}}
|
|
|
|
|
{{ $products->links() }}
|
|
|
|
|
@endsection
|