laravel 函数测试 --- Route::has()

新建: D:\laragon\www\test\resources\views\t.blade.php

    @if (Route::has('login'))
        <div class="top-right links">
            @auth
                <a href="{{ url('/home') }}">Home</a>
            @else
                <a href="{{ route('login') }}">Login</a>

            @endauth
        </div>
    @else
        <h3>没有定义login这个路由, 没办法这样访问  {{ url('/login') }}</h3>
   
    @endif

加上@符号,双{}将不解析<br>
Hello, @{{ name }} .

{{ isset($name) ? $name : 'Default' }}
除了使用三元运算符,Blade 还提供了更简单的方式:

{{ $name or 'Default' }}

新建:
D:\laragon\www\test\routes\web.php

<?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('/', function () {
    return view('welcome');
});

Route::get('/t', function () {
    return view('t');
});

Route::get('/login', function () {
    return view('t');
})->name('login');

//路由加参数:在/t.blade.php中可以使用变量 {{$name}}
Route::get('/tname', function () {
    return view('t', ['name' => 'shen']);
});

如果 去掉->name('login'); 则找不到路由,Route::has('login') 和name('login'); 要成对出现 。万物有名。

posted @ 2018-05-15 16:22  ntcat  阅读(2264)  评论(0编辑  收藏  举报