zoukankan      html  css  js  c++  java
  • laravel 函数测试 --- Route::has()

    新建: D:laragonwww est esourcesviews .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:laragonwww est outesweb.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'); 要成对出现 。万物有名。

  • 相关阅读:
    zookeeper学习笔记
    wsl笔记
    SSDB数据库笔记
    spring笔记
    redis笔记
    openresty配置
    openresty安装笔记
    mybatis笔记
    nginx配置
    STM32F373(青风)+CUBEMX快速上手
  • 原文地址:https://www.cnblogs.com/dreamfine/p/9041580.html
Copyright © 2011-2022 走看看