Exemples Reherche Laravel
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="{{asset('style.css')}}">
</head>
<body>
<header>
<h1>Gestion des étudiants</h1>
</header>
<hr>
<nav>
<ul>
<li><a href="#">Liste des étudiants</a> </li>
<li><a href="#">Ajouter un étudiant</a> </li>
</ul>
</nav>
<hr>
<main>
@yield('content')
</main>
</body>
</html>
@extends('master')
@section('content')
<form action="{{route('filter')}}" method="get">
<div>
Choisir filière
</div>
<div>
<select name="id_filiere" id="">
@foreach($filieres as $filiere)
<option value="{{$filiere->id_filiere}}">{{$filiere-
>libelle}}</option>
@endforeach
</select>
<button>Filtrer</button>
</div>
</form>
<table border='1' width='100%'>
<tr>
<th>Numéro</th>
<th>Nom</th>
<th>Prénom</th>
<th>Date naissance</th>
<th>Email</th>
<th>Filière</th>
</tr>
@foreach($etudiants as $etudiant)
<tr>
<td>{{$etudiant->numero}}</td>
<td>{{$etudiant->nom}}</td>
<td>{{$etudiant->prenom}}</td>
<td>{{$etudiant->date_naiss}}</td>
<td>{{$etudiant->email}}</td>
<td>{{$etudiant->id_filiere}}</td>
</tr>
@endforeach
</table>
@stop
<?php
namespace App\Http\Controllers;
use App\Models\Etudiant;
use App\Models\Filiere;
use Illuminate\Http\Request;
class EtudiantController extends Controller
{
public function index(){
$filieres=Filiere::all();
$etudiants=Etudiant::all();
return view("index",compact("filieres"),compact("etudiants"));
}
public function filter(Request $request){
$filieres=Filiere::all();
$etudiants=Etudiant::where('id_filiere','=',$request->id_filiere)->get();
return view("index",compact("filieres"),compact("etudiants"));
}
}
<?php
use App\Http\Controllers\EtudiantController;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| 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('/', [EtudiantController::class,'index'])->name('index');
Route::get('/filter', [EtudiantController::class,'filter'])->name('filter');