Académique Documents
Professionnel Documents
Culture Documents
Nhezou fichier index w nbadlou leha extension .blade.php w n7otouha f dossier resources/views
2-Baadika naamlou creation d’une migration en utilisant terminal mta3 visual studio code w nektbou
l commande hdhy:
Les Views :
Houma les vues qui seront affichés qui n7elou site mte3na w yadhroulna w ykoun mn code
(HTML,CSS/Bootsrap….) w hedhm les vues li bch nesst7a9ouhm l kol :
Afficheprof.blade.php
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="{{ URL::to('css/bootstrap.min.css')}}">
</head>
<body>
<div class="container">
<br/>
<h2 class="text-center">Liste des profs ISI KEF</h2>
<br/>
<a href="{{route('AfficheAjoutProf')}}" class="btn btn-success ">Ajouter un au
tre Prof</a>
<table class="table table-hover">
<tr>
<th>ID</th>
<th>Nom</th>
<th>Prénom</th>
<th>Spécialité</th>
<th>Actions</th>
</tr>
@foreach ($profs as $prof)
<tr>
<td>{{$prof->id}}</td>
<td>{{$prof->nom}}</td>
<td>{{$prof->prenom}}</td>
<td>{{$prof->specialite}}</td>
<td>
<a href="{{route('AfficheEditProf',['id'=>$prof->id])}}"><span class="btn btn-
warning glyphicon glyphicon-pencil">Modifier</span></a>
<a href="{{route('AfficheDeleteProf',['id'=>$prof->id])}}"><span class="btn bt
n-danger glyphicon glyphicon-remove">Supprimer</span></a>
</td>
</tr>
@endforeach
</table>
</div>
</body>
</html>
AfficheAjoutProf.blade.php
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="{{ URL::to('css/bootstrap.min.css')}}">
</head>
<body>
<div class="container">
<h2 class="text-center">Ajout d'prof</h2>
<form action="{{route('AjoutProf')}}" method="post" >
<input type="hidden" name="_token" value="{{ Session::token() }}">
<div class="form-group">
<label>Nom</label>
<input class="form-control" type="text" name="nom" required>
</div>
<div class="form-group">
<label>Prenom</label>
<input type="text" class="form-control" name="prenom" required>
</div>
<div class="form-group">
<label>specialite</label>
<input type="text" class="form-control" name="specialite" required>
</div>
<a href="{{route('AfficheAjoutProf')}}" class="btn btn-default">Annuler</a>
<button type="submit" class="btn btn-success pull-right">Ajouter</button>
</form></body>
</html>
AfficheEditProfProf.blade.php
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="{{ URL::to('css/bootstrap.min.css')}}">
</head>
<body>
<div class="container">
<br/>
<h2 class="text-center">Modification d'un prof</h2>
<br/>
<form action="{{route('EditProf')}}" method="post" >
<input type="hidden" name="_token" value="{{ Session::token() }}">
<input type="hidden" name="id" value="{{ $prof->id }}">
<div class="form-group">
<label>Nom</label>
<input class="form-control" type="text" name="nom" value="{{ $prof->nom }}" re
quired>
</div>
<div class="form-group">
<label>Prenom</label>
<input type="text" class="form-control" name="prenom" value="{{ $prof->prenom
}}" required>
</div>
<div class="form-group">
<label>specialite</label>
<input type="text" class="form-control" name="specialite" value="{{ $prof-
>specialite }}" required>
</div>
<a href="{{route('AfficheProf')}}" class="btn btn-default">Annuler</a>
<button type="submit" class="btn btn-warning pull-right">Modifier</button>
</form>
</body>
</html>
AfficheDeleteProf.blade.php
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="{{ URL::to('css/bootstrap.min.css')}}">
</head>
<body>
<div class="container">
<br/>
<h2 class="text-center">Suppression d'un prof</h2>
<br/>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<table class="table table-hover">
<tr><th>ID</th><td>{{ $prof->id }}</td></tr>
<tr><th>Nom</th><td>{{ $prof->nom }}</td></tr>
<tr><th>Prenom</th><td>{{ $prof->prenom }}</td></tr>
<tr><th>Spécialité</th><td>{{ $prof->specialite }}</td></tr>
</table>
<form action="{{route('DeleteProf')}}" method="post" >
<input type="hidden" name="_token" value="{{ Session::token() }}">
<input type="hidden" name="id" value="{{ $prof->id }}">
<a href="{{route('AfficheProf')}}" class="btn btn-default">Annuler</a>
<button type="submit" class="btn btn-danger pull-right">Supprimer</button>
</form>
</div>
</div>
</body>
</html>
Les controlleurs : w lahne bch yssirou les fonctions mteena et pour cette application
On a 3 4 fonction (creer,modifier,afficher,supprimer) w 3ana un seul controlleur pour cette
application essmou ProfController.php whedha l code li mawjoud fyh :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProfController extends Controller
{
public function AfficheAjoutProf() {
return view ('AfficheAjoutProf') ;
}
public function AjoutProf(Request $request)
{
$prof = new \App\Prof();
$prof->nom=$request['nom'];
$prof->prenom=$request['prenom'];
$prof->specialite=$request['specialite'];
$prof->save();
$profs=\App\Prof::all();
return view('AfficheProf',compact('profs'));
}
public function AfficheEditProf(Request $request)
{
$id=$request['id'];
$prof=\App\Prof::find($id);
return view('AfficheEditProf',compact('prof'));
}
public function EditProf(Request $request)
{
$id=$request['id'];
$prof=\App\Prof::find($id);
$prof->nom=$request['nom'];
$prof->prenom=$request['prenom'];
$prof->specialite=$request['specialite'];
$prof->update();
$profs=\App\Prof::all();
return view('AfficheProf',compact('profs'));
}
public function AfficheProf() {
$profs=\App\Prof::all();
return view ('AfficheProf',compact('profs')) ;
}
public function AfficheDeleteProf(Request $request)
{
$id=$request['id'];
$prof=\App\Prof::find($id);
return view('AfficheDeleteProf',compact('prof'));
}
public function DeleteProf(Request $request)
{
$id=$request['id'];
$prof=\App\Prof::find($id);
$prof->delete();
$profs=\App\Prof::all();
return view('AfficheProf',compact('profs'));
}}
Les Routes : ykounou f chemin hedha routes/web.php w hedhm les routes li bch nesst7a9ouhm fl
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/','indexController@index');
Route::get('/AfficheAjoutProf',
['uses'=>'ProfController@AfficheAjoutProf',
'as'=>'AfficheAjoutProf'
]);
Route::POST('/AjoutProf',[
'uses' => 'ProfController@AjoutProf',
'as' => 'AjoutProf'
]);
Route::GET('/AfficheEditProf/{id}',[
'uses' => 'ProfController@AfficheEditProf',
'as' => 'AfficheEditProf'
]);
Route::POST('/EditProf',[
'uses' => 'ProfController@EditProf',
'as' => 'EditProf'
]);
Route::get('/AfficheProf',
['uses'=>'ProfController@AfficheProf',
'as'=>'AfficheProf'
]);
Route::GET('/AfficheDeleteProf/{id}',[
'uses' => 'ProfController@AfficheDeleteProf',
'as' => 'AfficheDeleteProf'
]);
Route::Post('/DeleteProf',[
'uses' => 'ProfController@DeleteProf',
'as' => 'DeleteProf'
]);