Exemples Les Routes 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Exemples Les routes 2

CD c:\xampp1\htdocs\laravelG1
laravel new routes2
cd routes2
php artisan make:controller RouteController

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

</head>
<body>
<h1>Index</h1>
<hr>
<nav>
<ul>
<li>
<a href="{{route('index')}}">Accueil</a>
</li>
<li>
<a href="{{route('blogs')}}">Blogs</a>
</li>
<li>
<a href="{{route('about')}}">About</a>
</li>
</ul>
</nav>
</body>
</html>

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class RouteController extends Controller


{
function blogs(){
return view("blogs");
}
function about() {
return view("about");
}
function goToPage1(){
return redirect()->route('page1');
}
}

<?php

use App\Http\Controllers\RouteController;
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('/', function () {
return view('index');
})->name('index');
Route::get('/blogs', [RouteController::class,'blogs'])->name('blogs');
Route::get('/about', [RouteController::class,'about'])->name('about');
Route::get('/page1',function(){
return view('page1');
})->name('page1');
Route::get('/pageone', [RouteController::class,'goToPage1']);

Exemple 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

</head>
<body>
<h1>Liste des étudiants</h1>
<hr>
lore
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>L'étudiant numéro {{$id}}</h1>
<hr>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=
, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Inscription</h1>
<hr>
<form action="">
<p>
<input type="text" name="" id="">
</p>
<p>
<button>Send</button>
</p>
</form>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Not found</h1>
<h2>404</h2>
</body>
</html>

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class RouteController extends Controller


{
public function index(){
return view("index");
}
public function create(){
return view("create");
}
function show($id ) {
return view("show",["id"=>$id]);
}
}

<?php

use App\Http\Controllers\RouteController;
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('/', function () {
return view('welcome');
});
Route::prefix('etudiants')->group(function () {
Route::get('/',[RouteController::class,'index'])->name('index');
Route::get('/create',[RouteController::class,'create'])-
>name('create');
Route::get('/show/{id}',[RouteController::class,'show'])-
>name('show');
});
Route::fallback(function () {
return view('notfound');
});

Exemple 3
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Inscription</h1>
<hr>
<form action="{{route('store')}}" method="post">
@method('PUT')
@csrf
<p>
<input type="text" placeholder="Nom...">
</p>
<p>
<input type="text" placeholder="Prénom...">

</p>
<p>
<button>Send</button>
</p>
</form>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Created ...</h1>
<hr>
</body>
</html>

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class RouteController extends Controller


{
function store(){
return view("store");
}
}

<?php

use App\Http\Controllers\RouteController;
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('/', function () {
return view('welcome');
});
Route::get('/create', function () {
return view('create');
});
Route::put('/store',[RouteController::class,'store'])->name('store');
Route::get('/name',function(){
$name= Route::currentRouteName();
return $name;
})->name('routename');

You might also like