【问题标题】:How to insert favicon in laravel?如何在 laravel 中插入网站图标?
【发布时间】:2020-06-26 10:35:30
【问题描述】:

我想为此目的在设计中动态插入 favicon 我创建了页面并使其连接到此页面中的数据库我可以上传 favicon 的图像并将其插入数据库但是当我想回调此 favicon 图片时对于其他页面标题,什么都不会改变

以下代码在应用服务提供者页面中:

$settings = Setting::all();  
foreach ($settings as $key => $setting) { 

       elseif($key === 0) $favicon = $setting->value;

       elseif($key === 1) $admin_logo = $setting->value;  
   }





   $shareData = array( 

    'favicon'=>$favicon,

    'admin_logo'=>$admin_logo

   );

我想在其他页面中回调它:

<link rel="shortcut icon" href="{{ asset('others') }}/{{ $shareData['favicon'] }}">

【问题讨论】:

    标签: php laravel laravel-5.8


    【解决方案1】:

    这是我的示例代码,在 AppServiceProvider.php 中的 boot() 方法中,遵循以下示例代码

    public function boot()
    {
        \View::composer('*', function ($view) {
    
         $settings = Setting::all();  
           foreach ($settings as $key => $setting) { 
    
            if($key === 0) $favicon = $setting->value;
            if($key === 1) $admin_logo = $setting->value;  
          }
    
         $shareData = array( 
          'favicon'=>$favicon,
          'admin_logo'=>$admin_logo
         );
    
                $view->with('shareData',$shareData);
         }
        });
    }
    

    【讨论】:

    • 如果我写 会返回图片
    【解决方案2】:

    我的代码是正确的,但加载该图标是 chrome 浏览器的问题

    【讨论】:

    • 如果解决了您的问题,请将答案标记为已接受的答案。
    猜你喜欢
    • 1970-01-01
    • 2020-06-16
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    相关资源
    最近更新 更多