【问题标题】:Laravel loading helper not automaticallyLaravel 加载助手不会自动
【发布时间】:2019-02-26 11:36:01
【问题描述】:

我试图在没有作曲家自动加载的情况下加载我的助手

对于我使用的控制器:

use \App\Helper;

效果很好,但是对于刀片的视图,我该如何加载它?

【问题讨论】:

    标签: laravel helper


    【解决方案1】:

    在刀片视图中,您可以使用 \App\Helper::call();

    @php
        $var = \App\Helper::call();
    @endphp
    

    【讨论】:

      【解决方案2】:

      你可以通过两种方式做到这一点

      解决方案 1:制作别名

      config\app.php 中将aliases 更改为

      'aliases' => [
          'App' => Illuminate\Support\Facades\App::class,
          'Artisan' => Illuminate\Support\Facades\Artisan::class,
          'Auth' => Illuminate\Support\Facades\Auth::class,
          ...................
          'Helper' => App\Helper::class,
      ]
      

      在刀片使用中

      @php
          $result = Helper::staticFunction();
          // or
          $helper = app(Helper::class);
          $helper->functionName(); 
      @endphp
      

      解决方案 2:

      @php
          $result = \App\Helper::staticFunction();
          // ot
          $helper = app(\App\Helper::class);
          $helper->functionName();
      @endphp
      

      【讨论】:

        【解决方案3】:

        尝试清除缓存

        php artisan cache:clear php artisan config:clear php artisan route:clear

        【讨论】:

          猜你喜欢
          • 2017-11-09
          • 2013-06-18
          • 1970-01-01
          • 1970-01-01
          • 2017-01-11
          • 1970-01-01
          • 2015-09-26
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多