fin tp
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Client;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class FrontendController extends Controller
|
class FrontendController extends Controller
|
||||||
{
|
{
|
||||||
public function accueil() {
|
public function accueil() {
|
||||||
@@ -17,6 +18,14 @@ class FrontendController extends Controller
|
|||||||
|
|
||||||
//pour créer un client
|
//pour créer un client
|
||||||
public function creer() {
|
public function creer() {
|
||||||
return view('creer');
|
return view('creationClient');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ajout(Request $request){
|
||||||
|
$data = $request->validate(['nom'=>'required', 'prenom'=>'required','email'=>'required|email|unique:clients','telephone'=>'nullable|regex:/^[0][1-9][0-9]{8}$/']);
|
||||||
|
Client::create($data);
|
||||||
|
return view('clients');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin-top: 10px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
th, td {
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
padding: 8px 12px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
th {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tr:nth-child(even) {
|
||||||
|
background-color: #fafafa;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav {
|
||||||
|
display: flex;
|
||||||
|
gap: 20px;
|
||||||
|
padding: 15px 25px;
|
||||||
|
border-bottom: 1px solid #ccc;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nav a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nav a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
@extends('layout')
|
@extends('layout')
|
||||||
|
|
||||||
@section('content'){{-- contenu injecté dans la vue layout --}}
|
@section('content'){{-- contenu injecté dans la vue layout --}}
|
||||||
|
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
|
||||||
<h1>Bienvenue dans la gestion de clients</h1>
|
<h1>Bienvenue dans la gestion de clients</h1>
|
||||||
<p>Utilisez le menu pour naviguer entre les pages.</p>
|
<p>Utilisez le menu pour naviguer entre les pages.</p>
|
||||||
@endsection
|
@endsection
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
@extends('layout')
|
@extends('layout')
|
||||||
@section('content')
|
@section('content')
|
||||||
|
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
|
||||||
<h1>Liste des clients</h1>
|
<h1>Liste des clients</h1>
|
||||||
<ul id="clients-list"></ul>
|
<ul id="clients-list"></ul>
|
||||||
{{-- Définition et exécution d'une fonction javascript pour afficher les clients --}}
|
{{-- Définition et exécution d'une fonction javascript pour afficher les clients --}}
|
||||||
@@ -10,10 +11,25 @@
|
|||||||
const response = await fetch('http://192.168.56.56:8000/api/clients');
|
const response = await fetch('http://192.168.56.56:8000/api/clients');
|
||||||
const clients = await response.json();
|
const clients = await response.json();
|
||||||
const list = document.getElementById('clients-list');
|
const list = document.getElementById('clients-list');
|
||||||
list.innerHTML = '';
|
list.innerHTML = `<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope=\"col\">Nom du client</th>
|
||||||
|
<th scope=\"col\">Adresse e-mail</th>
|
||||||
|
<th scope=\"col\">Voir le client</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody> `;
|
||||||
|
const table = list.querySelector("table")
|
||||||
clients.forEach(c => {
|
clients.forEach(c => {
|
||||||
list.innerHTML += `<li>${c.nom} (${c.email})</li>`;
|
table.innerHTML += `<tr>
|
||||||
|
<td>${c.nom}</td>
|
||||||
|
<td>${c.email}</td>
|
||||||
|
<td><a href="{{ url('/clients/${c.id}') }}">le client ${c.id}<a></td>
|
||||||
|
</tr>`;
|
||||||
});
|
});
|
||||||
|
list.innerHTML += "</tbody> </table>"
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur :', error);
|
console.error('Erreur :', error);
|
||||||
list.innerHTML = '<li>Impossible de charger les clients</li>';
|
list.innerHTML = '<li>Impossible de charger les clients</li>';
|
||||||
|
|||||||
22
resources/views/creationClient.blade.php
Normal file
22
resources/views/creationClient.blade.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
@extends('layout')
|
||||||
|
@section('content')
|
||||||
|
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
|
||||||
|
<h1>Création d'un nouveau client</h1>
|
||||||
|
<form action="{{ url('ajout')}}" method="POST">
|
||||||
|
@csrf
|
||||||
|
<label for="nom">Nom:</label>
|
||||||
|
<input type="text" name="nom" id="nom" required>
|
||||||
|
|
||||||
|
<label for="prenom">Prenom:</label>
|
||||||
|
<input type="text" name="prenom" id="prenom" required>
|
||||||
|
|
||||||
|
<label for="email">E-mail:</label>
|
||||||
|
<input type="text" name="email" id="email" required>
|
||||||
|
|
||||||
|
<label for="telephone">Numero de Telephone:</label>
|
||||||
|
<input type="text" name="telephone" id="telephone">
|
||||||
|
|
||||||
|
<input type="submit" value="Soumettre">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@endsection
|
||||||
@@ -7,9 +7,14 @@
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<nav>
|
<nav>
|
||||||
<a href="{{ url('/') }}">Accueil</a>
|
<a href="{{ url('/') }}">Accueil</a>
|
||||||
<a href="{{ url('/clients') }}">Liste des clients</a>
|
<a href="{{ url('/clients') }}">Liste des clients</a>
|
||||||
</nav>
|
<a href="{{ url('/ajoutClient') }}">Crée un client</a>
|
||||||
|
<a href="{{ url('/clients') }}">Mise à jour complète d'un client</a>
|
||||||
|
<a href="{{ url('/clients') }}">Mise à jour partielle d'un client</a>
|
||||||
|
<a href="{{ url('/clients') }}">Supprimer un client</a>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@yield('content'){{-- contenu des autres vues ici --}}
|
@yield('content'){{-- contenu des autres vues ici --}}
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ Route::get('/', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/', [FrontendController::class, 'accueil']);
|
Route::get('/', [FrontendController::class, 'accueil']);
|
||||||
Route::get('/clients', [FrontendController::class, 'clients']);
|
Route::get('/clients', [FrontendController::class, 'clients']);
|
||||||
|
Route::get('/ajoutClient', [FrontendController::class, 'creer']);
|
||||||
Reference in New Issue
Block a user