Gestions des livraisons(Laravel)
Application des gestions des livraisons réalisé par :F.E - DEVWOFS-202
Description du projet
- Application de "gestion des livraisons" permet de gérer les opérations de transport.
Tables
chauffeur(id,nom,prenom) camion(maticule,marque,photo) Permis(numero,type,dateExpiration,#idChauffeur) Livraison(id,date,VilleDepar,VilleArrivée,#idChauffeur,#idCamion,ArriveOUNon)
Design
Migrations
php artisan make:migration create_camions_tablephp artisan make:migration create_chauffeurs_tablephp artisan make:migration create_permis_tablephp artisan make:migration create_livraisons_tablecreate_camions_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('camions' , function (Blueprint $table){
$table->id('matricule');
$table->string('marque');
$table->string('photo');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('camions');
}
};
create_chauffeurs_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chauffeurs' , function (Blueprint $table){
$table->id('idCh');
$table->string('nom');
$table->string('prenom');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chauffeurs');
}
};
create_permis_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('permis' , function (Blueprint $table){
$table->id('numero');
$table->string('type');
$table->date('dateExpiration');
$table->unsignedBigInteger('idCh');
$table->foreign('idCh')->references('idCh')->on('chauffeurs')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('permis');
}
};
create_livraisons_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('livraisons' , function (Blueprint $table){
$table->id('idL');
$table->date('date');
$table->string('ville_depart');
$table->string('ville_arrivee');
$table->unsignedBigInteger('idCh');
$table->unsignedBigInteger('matricule');
$table->foreign('idCh')->references('idCh')->on('chauffeurs')->onDelete('cascade');
$table->foreign('matricule')->references('matricule')->on('camions')->onDelete('cascade');
$table->enum('arrivee', ['Oui', 'Non']);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('livraisons');
}
};
Models
php artisan make:model Camionphp artisan make:model Chauffeurphp artisan make:model Permisphp artisan make:model LivraisonCamion.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Camion extends Model
{
use HasFactory;
protected $table = 'camions';
protected $primaryKey = 'matricule';
protected $fillable = ['marque', 'photo'];
}
Chauffeur.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Camion;
class Chauffeur extends Model
{
use HasFactory;
protected $table = 'chauffeurs';
protected $primaryKey = 'idCh';
protected $fillable = ['nom', 'prenom'];
public function camions()
{
return $this->hasMany(Camion::class, 'idCh', 'idCh');
}
public function livraisons()
{
return $this->hasMany(livraison::class, 'idCh', 'idCh');
}
public function permis()
{
return $this->hasMany(permis::class, 'idCh', 'idCh');
}
}
Permis.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Control_V1\Chauffeur;
class Permis extends Model
{
use HasFactory;
protected $table = 'permiss';
protected $primaryKey = 'numero';
protected $fillable = ['type', 'dateExpiration', 'idCh'];
public function chauffeur()
{
return $this->belongsTo(Chauffeur::class, 'idCh', 'idCh');
}
}
Livraison.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Chauffeur;
use App\Models\Camion;
class Livraison extends Model
{
use HasFactory;
protected $table = 'livraisons';
protected $primaryKey = 'idL';
protected $fillable = ['date', 'ville_depart','ville_arrivee', 'idCh', 'matricule', 'arrivee'];
public function chauffeur()
{
return $this->belongsTo(Chauffeur::class, 'idCh', 'idCh');
}
public function camion()
{
return $this->belongsTo(Camion::class, 'matricule', 'matricule');
}
}
Controllers
php artisan make:Controller CamionControllerphp artisan make:Controller LivraisonControllerCamionController.php
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Camion;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
class CamionController extends Controller
{
//Ajouter un nouveau camion
public function Ajouter()
{
return view("camion/ajouter");
}
//Afficher la liste des camions
public function AfficherList()
{
$camion=Camion::all();
return view('camion/afficher', compact('camion'));
}
//Sauvegarder les informations du camion
public function Sauvegarder(Request $request)
{
$validate = Validator::make($request->all(), [
'marque' => 'required',
'photo' => 'required|image|mimes:jpeg,png,jpg|max:1000',
],[
'marque.required' => 'la marque est obligatoire.',
]);
if($validate->fails()){
return back()->withErrors($validate->errors())->withInput();
}
//Remarque
//Création du dossier 'images' dans le le dossier 'public'
$file = $request->file('photo');
$extension=$file->getClientOriginalExtension();
$taille=$file->getSize();
if($extension!='jpg' and $extension!='png' and $extension!='jpeg' and $taille>1000000)
{
return back()->with('msg','taille '.$taille.' image doit etre jpg,png,jpeg et de taille<10M');
}else{
$dossier = 'images';
$n_unique=uniqid();
$photoPath=$dossier.'/'.$n_unique."_".$file->getClientOriginalName();
$file->move("images",$n_unique."_".$file->getClientOriginalName());
}
$data=$request->post();
$data['photo']=$photoPath;
Camion::create($data);
return redirect()->route('camion.read')->with('success', 'Camion ajouté avec succès.');
}
//Supprimer un camion
public function Supprimer($matricule)
{
$camion = Camion::find($matricule);
$camion->delete();
return redirect()->route('camion.read');
}
//Modifier un camion
public function Modifier($matricule)
{
$c = Camion::find($matricule);
return view("camion/modifier", compact('c'));
}
//Sauvegarder les modifications des informations du camion
public function MettreAjour(Request $request, $matricule)
{
$camion = Camion::find($matricule);
$validate = Validator::make($request->all(), [
'marque' => 'required',
'photo' => 'image|mimes:jpeg,png,jpg|max:1000',
],[
'marque.required' => 'La marque est obligatoire.',
]);
if($validate->fails()){
return back()->withErrors($validate->errors())->withInput();
}
if ($request->hasFile('photo')) {
$file = $request->file('photo');
$extension = $file->getClientOriginalExtension();
$taille = $file->getSize();
if (!in_array($extension, ['jpg', 'png', 'jpeg']) || $taille > 1000000) {
return back()->with('msg', 'L\'image doit être au format jpg, png ou jpeg et de taille inférieure à 1 Mo.');
}
$dossier = 'images';
$n_unique = uniqid();
$photoPath = $dossier . '/' . $n_unique . "_" . $file->getClientOriginalName();
$file->move("images", $n_unique . "_" . $file->getClientOriginalName());
$camion->photo = $photoPath;
}
$camion->marque = $request->input('marque');
$camion->save();
return redirect()->route('camion.read')->with('success', 'Camion mis à jour avec succès.');
}
//Afficher la liste des camions les plus utilisés
public function popularc()
{
$camionspop = DB::select("SELECT c.matricule, c.marque, c.photo, COUNT(*) AS utilisations
FROM camions c
JOIN livraisons l ON c.matricule = l.matricule
GROUP BY c.matricule, c.marque, c.photo
ORDER BY utilisations DESC
LIMIT 5");
return view('camion.camionspopulaires', compact('camionspop'));
}
}
LivraisonController.php
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Livraison;
use App\Models\Chauffeur;
use App\Models\Camion;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
class LivraisonController extends Controller
{
//Ajouter une nouvelle livraison
public function Ajouter()
{
$listeChauffeurs = Chauffeur::all();
$listeCamions = Camion::all();
return view("livraison/ajouter", ['listeChauffeurs' => $listeChauffeurs, 'listeCamions' => $listeCamions]);
}
//Afficher la liste des livraisons
public function AfficherList()
{
$livraison=Livraison::all();
return view('livraison/afficher', compact('livraison'));
}
//Sauvegarder les informations d'une livraison
public function Sauvegarder(Request $request)
{
$validate = Validator::make($request->all(), [
'date' => 'required',
'ville_depart' => 'required',
'ville_arrivee' => 'required',
'idCh' => 'required',
'matricule' => 'required',
'arrivee' => 'required',
],[
'date.required' => 'la date est obligatoire.',
'ville_depart.required' => 'la ville est obligatoire.',
'ville_arrivee.required' => 'la ville est obligatoire.',
'idCh.required'=> 'La designation du chauffeur est obligatoire.',
'matricule.required'=> 'La matricule du camion est obligatoire.',
'arrivee.required' => 'Le statut de la livraison est obligatoire.',
]);
if($validate->fails()){
return back()->withErrors($validate->errors())->withInput();
}
$data=$request->post();
Livraison::create($data);
return redirect()->route('livraison.read')->with('success', 'Livraison ajouté avec succès.');
}
//Supprimer une livraison
public function Supprimer($idL)
{
$livraison = Livraison::find($idL);
$livraison->delete();
return redirect()->route('livraison.read');
}
//Modifier une livraison
public function Modifier($idL)
{
$listeChauffeurs = Chauffeur::all();
$listeCamions = Camion::all();
$l = Livraison::find($idL);
return view("livraison/modifier", compact('l'), ['listeChauffeurs' => $listeChauffeurs, 'listeCamions' => $listeCamions]);
}
//Sauvegarder les modifications des informations d'une livraison
public function MettreAjour(Request $request, $idL)
{
$livraison = Livraison::find($idL);
$livraison->update([
'date' => $request->input('date'),
'ville_depart' => $request->input('ville_depart'),
'ville_arrivee' => $request->input('ville_arrivee'),
'idCh' => $request->input('idCh'),
'matricule' => $request->input('matricule'),
'arrivee' => $request->input('arrivee'),
]);
return redirect()->route('livraison.read');
}
//Séléctionner un chauffeur pour afficher la liste des camions qu'il a utilisé
public function selectchauffeur(Request $request)
{
$idCh = $request->input("idCh");
$chauffeur = Chauffeur::find($idCh);
if ($chauffeur) {
$livraisons = Livraison::where('idCh', $chauffeur->idCh)->get();
$listecamions = array();
foreach ($livraisons as $livraison) {
$camion = Camion::find($livraison->matricule);
if ($camion) {
$listecamions[] = $camion;
}
}
$listecamions = array_unique($listecamions);
} else {
$listecamions = [];
}
$listeChauffeurs = Chauffeur::all();
return view("chauffeur/listecamions", compact("listecamions", "listeChauffeurs"));
}
//Afficher la liste des livraisons d'une date séléctionnée
public function selectdate(Request $request)
{
$listeLivraisons = Livraison::all();
$date = $request->input("date");
$livraisons = Livraison::where('date', $date)->get();
return view("livraison/listelivraisondate", compact("livraisons", "listeLivraisons", "date"));
}
//Afficher la liste des livraisons à partir d'une ville de départ séléctionnée
public function selectvilled(Request $request)
{
$listeLivraisons = Livraison::all();
$villeDepart = $request->input("ville_depart");
$livraisons = Livraison::where('ville_depart', $villeDepart)->get();
return view("camion/listecamionsvilled", compact("livraisons", "listeLivraisons", "villeDepart"));
}
//Afficher la liste des livraisons à partir d'une ville d'arrivée séléctionnée où le status de la livraison est arrivée (arrivee = Oui)
public function selectvilleaoui(Request $request)
{
$listeLivraisons = Livraison::all();
$villeArrivee = $request->input('ville_arrivee');
$livraisons = Livraison::where('ville_arrivee', $villeArrivee)
->where('arrivee', 'Oui')
->get();
return view('camion/listecamionsvilleao', compact('livraisons','listeLivraisons'));
}
//Afficher la liste des chauffeurs avec le nombre de livraisons qui leur sont affectées
public function nbrlivraisonsparchauffeur()
{
$chauffeurL = DB::Select("SELECT c.idCh, c.nom, c.prenom, COUNT(*) AS nbrL
FROM chauffeurs c
JOIN livraisons l ON c.idCh = l.idCh
GROUP BY c.idCh, c.nom, c.prenom
ORDER BY c.idCh;");
return view("chauffeur/nombrelivraison", compact("chauffeurL"));
}
}
Views
Créer les views ressources/views

camion/afficher.blade.php
Liste des camions
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Afficher Camions</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ccc;
background-color: #fff;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #f2f2f2;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
img {
max-width: 100px;
height: auto;
}
.edit{
background-color: #4caf50;
color: #fff;
border: none;
padding: 12px 20px;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
.delete{
background-color: red;
color: #fff;
border: none;
padding: 12px 20px;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Liste Camions</h1>
<div>
<table>
<thead>
<tr>
<th>MATRICULE</th>
<th>MARQUE</th>
<th>PHOTO</th>
<th>ACTIONS</th>
</tr>
</thead>
<tbody>
@foreach ($camion as $c)
<tr>
<td>{{$c->matricule}}</td>
<td>{{$c->marque}}</td>
<td>
<img src="/{{$c->photo}}"/>
</td>
<td>
<form action="{{route('camion.delete',$c->matricule)}}" method="post">
@csrf
@method('DELETE')
<button class='delete'>Supprimer Camion</button>
</form><br>
<form action="{{route('camion.edit',$c->matricule)}}" method="get">
@csrf
<button class='edit'>Modifier Camion</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
<center><a href="/menu">Back to Menu</a></center>
</div>
</body>
</html>
camion/ajouter.blade.php
Formulaire d'ajout d'un nouveau camion
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Camion </title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
form {
max-width: 500px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"],
input[type="file"],
textarea {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box;
font-size: 16px;
}
textarea {
height: 100px;
}
input[type="submit"] {
background-color: #4caf50;
color: #fff;
border: none;
padding: 12px 20px;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.error-message {
color: red;
margin-bottom: 10px;
}
</style>
</head>
<body>
<center><h1>Nouveau Camion</h1></center>
<form action="{{ route('camion.save') }}" method="POST" enctype="multipart/form-data">
@csrf
<label for="marque">Marque : </label>
<input type="text" name="marque" required>
@error('marque')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="photo">Photo :</label>
<input type="file" name="photo" accept="image/*">
@error('photo')
<div class="error-message">{{ $message }}</div>
@enderror
<input type="submit" type='button' value="Ajouter Camion">
@if(session('msg'))
<p>{{ session('msg') }}</p>
@endif
<center><a href="/menu">Back to Menu</a></center>
</body>
camion/camionspopulaires.blade.php
Liste des camions les plus utilisés
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Camions les plus utilisés</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
h3 {
color: #333;
text-align: center;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ccc;
background-color: #fff;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #f2f2f2;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
img {
max-width: 100px;
height: auto;
}
</style>
</head>
<body>
<h3>Camions les plus utilisés :</h3>
<table>
<thead>
<tr>
<th>Matricule</th>
<th>Marque</th>
<th>Photo</th>
<th>Nombre d'utilisations</th>
</tr>
</thead>
<tbody>
@foreach($camionspop as $c)
<tr>
<td>{{ $c->matricule }}</td>
<td>{{ $c->marque }}</td>
<td><img src="/{{ $c->photo }}"/></td>
<td>{{ $c->utilisations }}</td>
</tr>
@endforeach
</tbody>
</table>
<center><a href="/menu">Back to Menu</a></center>
</body>
camion/listecamionsvilleao.blade.php
Liste des camions dont le status de la livraison est 'arrivee = Oui' par séléction d'une ville d'arrivée
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Camions arrivées à leur destination </title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ccc;
background-color: #fff;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #f2f2f2;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
img {
max-width: 100px;
height: auto;
}
</style>
</head>
<body>
<h3>Sélectionner une ville d'arrivée :</h3>
<form action="{{ route('livraison.varrivee') }}" method="GET">
@csrf
<label for="ville_arrivee">Sélectionner une ville :</label>
<select name="ville_arrivee" id="ville_arrivee">
@foreach($listeLivraisons as $l)
<option value="{{ $l->ville_arrivee }}">{{ $l->ville_arrivee }}</option>
@endforeach
</select>
<input type="submit" value="Afficher les livraisons">
</form>
<hr>
<fieldset>
<legend>Liste des Livraisons arrivées</legend>
<table>
<thead>
<tr>
<th>Matricule du camion</th>
<th>Marque du camion</th>
<th>Nom et Prenom du chauffeur</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
@foreach($livraisons as $l)
<tr>
<td>{{ $l->camion->matricule }}</td>
<td>{{ $l->camion->marque }}</td>
<td>{{ $l->chauffeur->nom }} {{ $l->chauffeur->prenom }}</td>
<td><img src="/{{ $l->camion->photo }}"></td>
</tr>
@endforeach
</tbody>
</table>
</fieldset>
<center><a href="/menu">Back to Menu</a></center>
</body>
</html>
camion/listecamionsvilled.blade.php
Liste des camions par séléction d'une ville de départ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Liste des livraisons par ville de départ</title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ccc;
background-color: #fff;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #f2f2f2;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
img {
max-width: 100px;
height: auto;
}
</style>
</head>
<body>
<h3>Sélectionner une ville de départ :</h3>
<form action="{{ route('livraison.vdepart') }}" method="GET">
@csrf
<label for="ville_depart">Sélectionner une ville :</label>
<select name="ville_depart" id="ville_depart">
@foreach($listeLivraisons as $l)
<option value="{{ $l->ville_depart }}">{{ $l->ville_depart }}</option>
@endforeach
</select>
<input type="submit" value="Afficher les livraisons">
</form>
<hr>
<fieldset>
<legend>Liste des Livraisons</legend>
<table>
<thead>
<tr>
<th>Matricule du camion</th>
<th>Marque du camion</th>
<th>Nom et Prenom du chauffeur</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
@foreach($livraisons as $l)
<tr>
<td>{{ $l->camion->matricule }}</td>
<td>{{ $l->camion->marque }}</td>
<td>{{ $l->chauffeur->nom }} {{ $l->chauffeur->prenom }}</td>
<td><img src="/{{ $l->camion->photo }}"></td>
</tr>
@endforeach
</tbody>
</table>
</fieldset>
<center><a href="/menu">Back to Menu</a></center>
</body>
</html>
camion/modifier.blade.php
Formulaire de modification d'un camion
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Camion</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
form {
max-width: 500px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"],
input[type="file"],
textarea {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box;
font-size: 16px;
}
textarea {
height: 100px;
}
button[type="submit"] {
background-color: #4caf50;
color: #fff;
border: none;
padding: 12px 20px;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
button[type="submit"]:hover {
background-color: #f2f2f2;
}
.error-message {
color: red;
margin-bottom: 10px;
}
</style>
</head>
<body>
<center><h1>Modifier Camion</h1></center>
<form action="{{ route('camion.update', $c->matricule) }}" method="POST" enctype="multipart/form-data">
@csrf
<label for="marque">Marque : </label>
<input type="text" name="marque" value='{{$c->marque}}' required>
@error('marque')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="photo">Photo :</label>
<input type="file" name="photo" value='{{$c->photo}}' accept="image/*">
@error('photo')
<div class="error-message">{{ $message }}</div>
@enderror
<button type="submit">Modifier Camion</button>
@if(session('msg'))
<p>{{ session('msg') }}</p>
@endif
<center><a href="/menu">Back to Menu</a></center>
</body>
chauffeur/listecamions.blade.php
Liste des camions par chauffeur séléctionné
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
img {
max-width: 100px;
height: auto;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ccc;
background-color: #fff;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #f2f2f2;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h3>Liste des camions d'un chauffeur </h3>
<form action="{{ route('livraison.chauffeur') }}" method="GET">
@csrf
<label for="idCh">Sélectionner un chauffeur :</label>
<select name="idCh" id="idCh">
@foreach($listeChauffeurs as $ch)
<option value="{{ $ch->idCh }}">{{ $ch->nom }}</option>
@endforeach
</select>
<input type="submit" value="Afficher les camions">
</form>
</hr>
<fieldset>
<legend>Liste des Camions</legend>
<table>
<thead>
<tr>
<th>Matricule</th>
<th>Marque</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
@foreach($listecamions as $c)
<tr>
<td>{{ $c->matricule }}</td>
<td>{{ $c->marque }}</td>
<td><img src="/{{ $c->photo }}"/></td>
</tr>
@endforeach
</tbody>
</table>
</fieldset>
<center><a href="/menu">Back to Menu</a></center>
</body>
chauffeur/nombrelivraison.blade.php
Liste des chauffeurs et le nombre de leurs livraisons
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nombre de livraisons par chauffeur</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
h3 {
color: #333;
text-align: center;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ccc;
background-color: #fff;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #f2f2f2;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h3>Nombre de livraisons pour chaque chauffeur :</h3>
<table>
<thead>
<tr>
<th>ID Chauffeur</th>
<th>Nom</th>
<th>Prénom</th>
<th>Nombre de livraisons</th>
</tr>
</thead>
<tbody>
@foreach($chauffeurL as $cl)
<tr>
<td>{{$cl->idCh}}</td>
<td>{{$cl->nom}}</td>
<td>{{$cl->prenom}}</td>
<td>{{$cl->nbrL}}</td>
</tr>
@endforeach
</tbody>
</table>
<center><a href="/menu">Back to Menu</a></center>
</body>
livraison/afficher.blade.php
Liste des Livraisons
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Afficher Livraisons</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ccc;
background-color: #fff;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #f2f2f2;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
img {
max-width: 100px;
height: auto;
}
.edit{
background-color: #4caf50;
color: #fff;
border: none;
padding: 12px 20px;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
.delete{
background-color: red;
color: #fff;
border: none;
padding: 12px 20px;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Liste Livraisons</h1>
<div>
<table>
<thead>
<tr>
<th>ID</th>
<th>DATE</th>
<th>VILLE DE DEPART</th>
<th>VILLE D'ARRIVEE</th>
<th>ID DU CHAUFFEUR DE LIVRAISON</th>
<th>MATRICULE DU CAMION DE LIVRAISON</th>
<th>STATUT DE LA LIVRAISON</th>
<th>ACTIONS</th>
</tr>
</thead>
<tbody>
@foreach ($livraison as $l)
<tr>
<td>{{$l->idL}}</td>
<td>{{$l->date}}</td>
<td>{{$l->ville_depart}}</td>
<td>{{$l->ville_arrivee}}</td>
<td>{{$l->idCh}}</td>
<td>{{$l->matricule}}</td>
<td>{{$l->arrivee}}</td>
<td>
<form action="{{route('livraison.delete',$l->idL)}}" method="post">
@csrf
@method('DELETE')
<button class='delete'>Supprimer Livraison</button>
</form><br>
<form action="{{route('livraison.edit',$l->idL)}}" method="get">
@csrf
<button class='edit'>Modifier Livraison</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
<center><a href="/menu">Back to Menu</a></center>
</div>
</body>
</html>
livraison/ajouter.blade.php
Formulaire d'ajout d'une nouvelle livraison
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Livraison </title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
form {
max-width: 400px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"],
input[type="file"],
textarea {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box;
font-size: 16px;
}
textarea {
height: 100px;
}
input[type="submit"] {
background-color: #4caf50;
color: #fff;
border: none;
padding: 12px 20px;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.error-message {
color: red;
margin-bottom: 10px;
}
</style>
</head>
<body>
<center><h1>Nouvelle Livraison</h1></center>
<form action="{{ route('livraison.save') }}" method="POST" enctype="multipart/form-data">
@csrf
<label for="date">Date de demande de livraison : </label>
<input type="date" name="date" required>
@error('date')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="ville_depart">Ville de départ : </label>
<input type="text" name="ville_depart" required>
@error('ville_depart')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="ville_arrivee">Ville d'arrivée : </label>
<input type="text" name="ville_arrivee" required>
@error('ville_arrivee')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="idCh">Chauffeur de livraison : </label>
<select name='idCh' id='idCh'>
@foreach($listeChauffeurs as $ch)
<option value="{{ $ch->idCh }}">{{ $ch->nom }}</option>
@endforeach
</select>
@error('idCh')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="matricule">Camion de livraison : </label>
<select name='matricule' id='matricule'>
@foreach($listeCamions as $c)
<option value="{{ $c->matricule }}">{{ $c->marque }}</option>
@endforeach
</select>
@error('matricule')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="arrivee">Statut de la livraison (Arrivée) : </label>
<input type="radio" name="arrivee" value="Oui"> Oui
<input type="radio" name="arrivee" value="Non"> Non
@error('arrivee')
<div class="error-message">{{ $message }}</div>
@enderror
<br>
<input type="submit" type='button' value="Ajouter Livraison">
@if(session('msg'))
<p>{{ session('msg') }}</p>
@endif
<center><a href="/menu">Back to Menu</a></center>
</form>
</body>
</html>
livraison/listelivraisondate.blade.php
Liste des livraisons par une date séléctionnée
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Liste des livraisons pour une date donnée</title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ccc;
background-color: #fff;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #f2f2f2;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h3>Liste des livraisons pour une date donnée</h3>
<form action="{{ route('livraison.date') }}" method="GET">
@csrf
<label for="date">Sélectionner une date :</label>
<select name="date" id="date">
@foreach($listeLivraisons as $l)
<option value="{{ $l->date }}">{{ $l->date }}</option>
@endforeach
</select>
<input type="submit" value="Afficher les livraisons">
</form>
<hr>
<fieldset>
<legend>Liste des Livraisons</legend>
<table>
<thead>
<tr>
<th>ID Livraison</th>
<th>Date</th>
<th>Ville de départ</th>
<th>Ville d'arrivée</th>
<th>Nom du chauffeur</th>
<th>Marque du camion</th>
<th>Statut de la Livraison</th>
</tr>
</thead>
<tbody>
@foreach($livraisons as $l)
<tr>
<td>{{ $l->idL }}</td>
<td>{{ $l->date }}</td>
<td>{{ $l->ville_depart }}</td>
<td>{{ $l->ville_arrivee }}</td>
<td>{{ $l->chauffeur->nom }} {{ $l->chauffeur->prenom }}</td>
<td>{{ $l->camion->marque }}</td>
<td>{{ $l->arrivee }}</td>
</tr>
@endforeach
</tbody>
</table>
</fieldset>
<center><a href="/menu">Back to Menu</a></center>
</body>
</html>
livraison/modifier.blade.php
Formulaire de modification d'une livraison
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modifier Livraison</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
form {
max-width: 400px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"],
input[type="file"],
textarea {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box;
font-size: 16px;
}
textarea {
height: 100px;
}
button[type="submit"] {
background-color: #4caf50;
color: #fff;
border: none;
padding: 12px 20px;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
button[type="submit"]:hover {
background-color: #45a049;
}
.error-message {
color: red;
margin-bottom: 10px;
}
</style>
</head>
<body>
<center><h1>Modifier Livraison</h1></center>
<form action="{{ route('livraison.update', $l->idL) }}" method="POST" enctype="multipart/form-data">
@csrf
<label for="date">Date de demande de livraison : </label>
<input type="date" name="date" value='{{$l->date}}' required>
@error('date')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="ville_depart">Ville de départ : </label>
<input type="text" name="ville_depart" value='{{$l->ville_depart}}' required>
@error('ville_depart')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="ville_arrivee">Ville d'arrivée : </label>
<input type="text" name="ville_arrivee" value='{{$l->ville_arrivee}}' required>
@error('ville_arrivee')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="idCh">Chauffeur de livraison : </label>
<select name="idCh" id="idCh">
@foreach($listeChauffeurs as $ch)
<option value="{{ $ch->idCh }}">{{ $ch->nom }}</option>
@endforeach
</select>
@error('idCh')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="matricule">Camion de livraison : </label>
<select name="matricule" id="matricule">
@foreach($listeCamions as $c)
<option value="{{ $c->matricule }}">{{ $c->matricule }}_{{ $c->marque }}</option>
@endforeach
</select>
@error('matricule')
<div class="error-message">{{ $message }}</div>
@enderror
<label for="arrivee">Statut de la livraison (Arrivée) : </label>
<input type="radio" name="arrivee" value="Oui" > Oui
<input type="radio" name="arrivee" value="Non" > Non
@error('arrivee')
<div class="error-message">{{ $message }}</div>
@enderror
<br>
<button type="submit">Modifier Livraison</button>
@if(session('msg'))
<p>{{ session('msg') }}</p>
@endif
<center><a href="/menu">Back to Menu</a></center>
</body>
Menu.blade.php
Menu pour faciliter la navigation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Menu</title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ccc;
background-color: #fff;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: center;
}
th {
background-color: #f2f2f2;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<fieldset>
<center><h1> Gestions des Livraisons</h1></center>
<table>
<thead>
<tr>
<th>Menu</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="/camions/afficherlist"> Liste des camions </a></td>
</tr>
<tr>
<td><a href="/livraisons/afficherlist"> Liste des Livraisons</a></td>
</tr>
<tr>
<td><a href="/camions/ajouter"> Ajouter un Camion</a></td>
</tr>
<tr>
<td><a href="/livraisons/ajouter"> Ajouter une Livraison</a></td>
</tr>
<tr>
<td><a href="/livraisons/chauffeurcamions"> Liste des camions par chauffeur </a></td>
</tr>
<tr>
<td><a href="/livraisons/villedepart"> Liste des camions pour une ville de départ sélectionnée</a></td>
</tr>
<tr>
<td><a href="/livraisons/villearriveeoui"> Liste des camions arrivés dans une ville sélectionnée</a></td>
</tr>
<tr>
<td><a href="/camions/popularcamions"> Liste des camions les plus utilisés</a></td>
</tr>
<tr>
<td><a href="/livraisons/datelivraison"> Liste des livraisons d’une date données</a></td>
</tr>
<tr>
<td><a href="/livraisons/nombreparchauffeur"> Liste des chauffeurs et le nombre de leurs livraisons </a></td>
</tr>
</tbody>
</table>
</fieldset>
</body>
</html>
Routes
Créer les routes routes/web.php
web.php
<?php
use App\Http\Controllers\CamionController;
use App\Http\Controllers\LivraisonController;
//Menu ROUTE (Navigation)
Route::get('/menu', function () {
return view('/menu');
});
//Camion ROUTES
Route::get('/camions/ajouter', [CamionController::class, 'Ajouter'])->name('camion.add');
Route::post('/camions/sauvegarder', [CamionController::class, 'Sauvegarder'])->name('camion.save');
Route::get('/camions/afficherlist', [CamionController::class, 'AfficherList'])->name('camion.read');
Route::get('/camions/{camion}/modifier', [CamionController::class, 'Modifier'])->name('camion.edit');
Route::post('/camions/{camion}', [CamionController::class, 'MettreAjour'])->name('camion.update');
Route::delete('/camions/{camion}', [CamionController::class, 'Supprimer'])->name('camion.delete');
Route::get('/camions/popularcamions', [CamionController::class, 'popularc'])->name('camion.popular');
//Livraison ROUTES
Route::get('/livraisons/ajouter', [LivraisonController::class, 'Ajouter'])->name('livraison.add');
Route::post('/livraisons/sauvegarder', [LivraisonController::class, 'Sauvegarder'])->name('livraison.save');
Route::get('/livraisons/afficherlist', [LivraisonController::class, 'AfficherList'])->name('livraison.read');
Route::get('/livraisons/{livraison}/modifier', [LivraisonController::class, 'Modifier'])->name('livraison.edit');
Route::post('/livraisons/{livraison}', [LivraisonController::class, 'MettreAjour'])->name('livraison.update');
Route::delete('/livraisons/{livraison}', [LivraisonController::class, 'Supprimer'])->name('livraison.delete');
Route::get('/livraisons/chauffeurcamions', [LivraisonController::class, 'selectchauffeur'])->name('livraison.chauffeur');
Route::get('/livraisons/datelivraison', [LivraisonController::class, 'selectdate'])->name('livraison.date');
Route::get('/livraisons/nombreparchauffeur', [LivraisonController::class, 'nbrlivraisonsparchauffeur'])->name('livraison.nbrparchauffeur');
Route::get('/livraisons/villedepart', [LivraisonController::class, 'selectvilled'])->name('livraison.vdepart');
Route::get('/livraisons/villearriveeoui', [LivraisonController::class, 'selectvilleaoui'])->name('livraison.varrivee');