Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views2 pages

Dossier Backend TP

The document outlines the creation of a migration for an 'affectations' table, including foreign key relationships with 'employes' and 'materiels'. It details the creation of models for 'Materiel', 'Employe', and 'Departement', along with a controller for managing 'Materiel' entities. Additionally, it provides the structure for displaying and managing 'materiels' and 'employes' through routes and views in a Laravel application.

Uploaded by

mesraramina4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Dossier Backend TP

The document outlines the creation of a migration for an 'affectations' table, including foreign key relationships with 'employes' and 'materiels'. It details the creation of models for 'Materiel', 'Employe', and 'Departement', along with a controller for managing 'Materiel' entities. Additionally, it provides the structure for displaying and managing 'materiels' and 'employes' through routes and views in a Laravel application.

Uploaded by

mesraramina4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

php artisan make:migration create_affectations_table

Contenu de la migration :

public function up()


{
Schema::create('affectations', function (Blueprint $table) {
$table->id();
$table->foreignId('employe_id')->constrained()->onDelete('cascade');
$table->foreignId('materiel_id')->constrained()->onDelete('cascade');
$table->date('date_debut');
$table->date('date_fin')->nullable();
$table->timestamps();
});
}

2. Création des modèles :

Commandes :
php artisan make:model Materiel
php artisan make:model Employe
php artisan make:model Departement

C exemple dans Employe.php :

public function departement() {


return $this->belongsTo(Departement::class);
}

public function affectations() {


return $this->hasMany(Affectation::class);
}

3.

php artisan make:controller MaterielController

Contenu du contrôleur :

public function AfficherListeMateriels() {


$materiels = Materiel::all();
return view('index', compact('materiels'));
}

public function AjouterMateriel(Request $request) {


Materiel::create($request->all());
return redirect()->action([MaterielController::class,
'AfficherListeMateriels']);
}

public function SupprimerMateriel($id) {


Materiel::destroy($id);
return redirect()->action([MaterielController::class,
'AfficherListeMateriels']);
}

4.

<table>
<tr>
<th>code</th><th>marque</th><th>description</th><th>date
début</th><th>action</th>
</tr>
@foreach($materiels as $materiel)
<tr>
<td>{{ $materiel->code }}</td>
<td>{{ $materiel->marque }}</td>
<td>{{ $materiel->description }}</td>
<td>{{ $materiel->date_debut_utilisation }}</td>
<td>
<form method="POST" action="{{ route('materiel.supprimer', $materiel-
>id) }}">
@csrf
@method('DELETE')
<button type="submit">supprimer</button>
</form>
</td>
</tr>
@endforeach
</table>

5.

public function AfficherListeEmployes() {


$employes = Employe::with('departement', 'affectations.materiel')->get();
return view('employes', compact('employes'));
}

public function ConsulterDetailsMateriels($id) {


$employe = Employe::with('affectations.materiel')->findOrFail($id);
return view('details', compact('employe'));
}

6.

Route::get('/materiels', [MaterielController::class, 'AfficherListeMateriels'])-


>name('materiel.liste');
Route::post('/materiels/ajouter', [MaterielController::class, 'AjouterMateriel'])-
>name('materiel.ajouter');
Route::delete('/materiels/supprimer/{id}', [MaterielController::class,
'SupprimerMateriel'])->name('materiel.supprimer');

Route::get('/employes', [EmployeController::class, 'AfficherListeEmployes'])-


>name('employe.liste');
Route::get('/employes/{id}/details', [EmployeController::class,
'ConsulterDetailsMateriels'])->name('employe.details');

You might also like