PHP - Laravel 视图模板(blade.php) if 语句

312 阅读1分钟
  • web.php 路由中传递参数

    Route::get('req', function () {
        // Json 参数
        $data = ['name'=>'dzm'];
        // 传递
        return view('index')->with(['data'=>$data]);
    });
    
  • blade.php 中使用

    <body>
      @if (isset($data['id']))
        有ID数据
      @elseif (isset($data['name']))
        有Names数据
      @else
        无数据
      @endif
    </body>
    
  • Demo 效果

    image.png