<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] # 視圖 ## 創建視圖 ``` Route::get('/', function () { return view('greeting', ['name' => 'James']); }); <!-- 此視圖文件位置 resources/views/greeting.blade.php --> <html> <body> <h1>Hello, {{ $name }}</h1> </body> </html> // 子目錄,可以用「點」符號來引用嵌套視圖 resources/views/admin/profile.blade.php return view('admin.profile', $data); ``` ### 判斷視圖文件是否存在 ``` use Illuminate\Support\Facades\View; if (View::exists('emails.customer')) { // } ``` ### 創建第一個可用視圖 ``` return view()->first(['custom.admin', 'admin'], $data); use Illuminate\Support\Facades\View; return View::first(['custom.admin', 'admin'], $data); ``` ## 向視圖傳遞參數 ``` return view('greetings', ['name' => 'Victoria']); return view('greeting')->with('name', 'Victoria'); ``` ### 與所有視圖共享數據 如果需要共享一段數據給應用程序的所有視圖,你可以在服務提供器的`boot`方法中調用視圖 Facade 的`share`方法。例如,可以將它們添加到`AppServiceProvider`或者為它們生成一個單獨的服務提供器: ``` <?php namespace App\Providers; use Illuminate\Support\Facades\View; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { View::share('key', 'value'); } /** * Register the service provider. * * @return void */ public function register() { // } } ``` >[success] 注意:注意,如果你創建了新的一個服務提供器來與所有視圖共享數據,或者存放注冊視圖合成器的代碼,那么你需要將這個服務提供器添加到配置文件`config/app.php`的`providers`數組中。 ## 視圖合成器 [參考文章](https://blog.csdn.net/weixin_41800559/article/details/106792309) ### 創建視圖服務 ``` $ php artisan make:provider ViewServiceProvider ``` ### 定義視圖服務 每次渲染第一參數的視圖時都會執行視圖合成器`compose`方法。 ``` // 將這個服務提供器添加到配置文件 config/app.php 的 providers 數組中 'providers' => [ ... // 自定義視圖服務 App\Providers\ViewServiceProvider::class, ], // 在boot方法設置共享數據 public function boot() { // 所有視圖共享數據 View::share('shareParam1', 'Laravel1'); // 使用類注冊視圖合成器 View::composer( ['index', 'index1'], 'App\Http\View\Composers\ShareComposer' ); // 使用閉包函數注冊視圖合成器 View::composer(['index', 'index1'], function ($view) { $view->with('shareParam3', 'Laravel3'); }); } ``` **將視圖合成器添加到多個視圖** ``` // 將一個視圖合成器添加到多個視圖 View::composer( ['profile', 'dashboard'], 'App\Http\View\Composers\MyViewComposer' ); // 通配符`*`,表示將一個視圖合成器添加到所有視圖 View::composer('*', function ($view) { // }); ``` >[success] 第一個參數:`*`表示全部視圖,`path/*`表示path目錄內的視圖,數組表示多個視圖 ### 定義視圖合成器 ``` // 手動創建目錄 App\Http\View\Composers,新增 ShareComposer.php 文件 <?php namespace App\Http\View\Composers; use Illuminate\View\View; class ShareComposer { /** * Create a new share composer. * * @return void */ public function __construct() { // } /** * Bind data to the view. * * @param View $view * @return void */ public function compose(View $view) { $view->with('shareParam2', 'Laravel2'); } } ``` ### 模板顯示數據 ``` // 在視圖文件中使用共享數據 {{ $shareParam1 }} {{ $shareParam2 }} {{ $shareParam3 }} ``` ## 視圖構造器 視圖構造器在視圖實例化之后執行,而視圖合成器在視圖即將渲染時執行。 ``` View::creator('profile', 'App\Http\View\Creators\ProfileCreator'); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看