基本路由
您将在 app/Http/routes.php 中定义应用中的大多数路由,这个文件加载了 App\Providers\RouteServiceProvider 类。 大多数基本的 Laravel 路由都只接受一个 URI 和 一个 闭包(Closure) 参数
基本 GET 路由
1.直接输出
Route::get('/hello',function()
{
return "这是我的第一个路由";
});
2.使用模板输出
先在/resources/view下创建模板文件hello.php:
然后添加路由:
Route::get('/hello',function()
{
return View::make('hello');
});
3.传递模板变量输出
在模板文件中标题用变量来代替:
<h1>{{ $title }}</h1>
<p>hello,world</p>
修改路由:
Route::get('/hello',function()
{
return View::make('hello')->with('title','我的第一个laravel');
});
没有输出预想结果,原因是模板文件必须以blade为后缀:
成功输出: