Réalisation du tp3, tp4, tp5 et tp6 avec documentation.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<h2>Ajouter un produit</h2>
|
||||
|
||||
{{-- TP5 : liste générale des erreurs de validation. --}}
|
||||
@if ($errors->any())
|
||||
<div role="alert">
|
||||
<strong>Des erreurs sont présentes :</strong>
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form method="POST" action="{{ route('products.store') }}">
|
||||
{{-- TP4 : formulaire de création protégé par un jeton CSRF. --}}
|
||||
@csrf
|
||||
|
||||
{{-- TP5 : anciennes valeurs et erreurs propres à chaque champ. --}}
|
||||
<label for="name">Nom</label>
|
||||
<input id="name" type="text" name="name" value="{{ old('name') }}" required>
|
||||
@error('name') <div role="alert">{{ $message }}</div> @enderror
|
||||
|
||||
<label for="price">Prix (EUR)</label>
|
||||
<input id="price" type="number" name="price" min="0" step="0.01" value="{{ old('price') }}" required>
|
||||
@error('price') <div role="alert">{{ $message }}</div> @enderror
|
||||
|
||||
<label for="stock">Stock</label>
|
||||
<input id="stock" type="number" name="stock" min="0" value="{{ old('stock') }}" required>
|
||||
@error('stock') <div role="alert">{{ $message }}</div> @enderror
|
||||
|
||||
<button type="submit">Enregistrer</button>
|
||||
</form>
|
||||
@endsection
|
||||
@@ -0,0 +1,38 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<h2>Modifier {{ $product->name }}</h2>
|
||||
|
||||
{{-- TP5 : erreurs de validation de la modification. --}}
|
||||
@if ($errors->any())
|
||||
<div role="alert">
|
||||
<strong>Des erreurs sont présentes :</strong>
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form method="POST" action="{{ route('products.update', $product) }}">
|
||||
{{-- TP4 : @method('PUT') permet la route products.update. --}}
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
{{-- TP5 : old() conserve la saisie après une erreur. --}}
|
||||
<label for="name">Nom</label>
|
||||
<input id="name" type="text" name="name" value="{{ old('name', $product->name) }}" required>
|
||||
@error('name') <div role="alert">{{ $message }}</div> @enderror
|
||||
|
||||
<label for="price">Prix (EUR)</label>
|
||||
<input id="price" type="number" name="price" min="0" step="0.01" value="{{ old('price', $product->price) }}" required>
|
||||
@error('price') <div role="alert">{{ $message }}</div> @enderror
|
||||
|
||||
<label for="stock">Stock</label>
|
||||
<input id="stock" type="number" name="stock" min="0" value="{{ old('stock', $product->stock) }}" required>
|
||||
@error('stock') <div role="alert">{{ $message }}</div> @enderror
|
||||
|
||||
<button type="submit">Mettre à jour</button>
|
||||
</form>
|
||||
@endsection
|
||||
@@ -1,26 +1,48 @@
|
||||
@extends('layouts.app')
|
||||
@section('content')
|
||||
<h3> Liste des produtis : </h3>
|
||||
<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 && $produit['stock'] != 0)
|
||||
Stock faible
|
||||
|
||||
@else
|
||||
Stock disponible
|
||||
<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>
|
||||
@endif
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
@endsection
|
||||
{{-- TP6 : la recherche est conservée dans les liens grâce à withQueryString(). --}}
|
||||
{{ $products->links() }}
|
||||
@endsection
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<h2>{{ $product->name }}</h2>
|
||||
<p>Prix : {{ $product->price }} EUR</p>
|
||||
<p>Stock : {{ $product->stock }}</p>
|
||||
<p>Disponibilité : {{ $product->stock < 5 ? '⚠ Stock faible' : 'Disponible' }}</p>
|
||||
<a href="{{ route('products.index') }}">Retour</a>
|
||||
@endsection
|
||||
Reference in New Issue
Block a user