jerodev / laravel-font-awesome
v2.0
2019-12-24 13:18 UTC
Requires
- fortawesome/font-awesome: ^5.12
- illuminate/support: 6.x
Requires (Dev)
- orchestra/testbench: 4.x
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2020-06-25 15:14:00 UTC
README
‼️ 此包不再维护。
我建议切换到 https://github.com/blade-ui-kit/blade-icons
Font Awesome Blade 指令用于 Laravel
此包会在服务器端渲染 Font Awesome 图标,这样可以避免在客户端添加额外的 JavaScript 或 webfont 资源,从而显著减小网站的大小。
这是通过在发送响应给客户端之前替换图标为其对应的 svg 格式来实现的。
<!-- Turns this --> @fas('circle') <!-- Into this --> <svg viewBox="0 0 512 512" class="svg-inline--fa fa-w-16 fa-circle"> <path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z"/> </svg>
要求
| 要求 | 版本 |
|---|---|
| PHP | >= 7.2 |
| Laravel | 6.x |
Laravel 5.x
对于 Laravel 5.6 及以上版本,使用此包的 v1.x 版本
安装
使用 Composer 安装此包。
composer require jerodev/laravel-font-awesome
服务提供者
此包将由 Laravel 自动发现。如果您禁用了自动发现,您应该在 config/app.php 文件中添加以下提供者。
\Jerodev\LaraFontAwesome\FontAwesomeServiceProvider::class,
使用
中间件
⚠️ 自 2.0 版本起,中间件不再自动注入。您需要将其添加到需要的位置的路由中。
此包包含一个中间件 InjectStyleSheet,在渲染视图时将其注入到视图中。
可以按照 Laravel 的文档将中间件添加到路由中
Route::middleware(InjectStyleSheet::class)->group(static function () { // Create routes here. });
视图
要在视图中使用 Font Awesome 图标,有几个新的 Blade 指令。
// Let the package discover the best library for this icon. @fa('laravel') // Define the library that should be used. @far('circle') // Regular @fas('circle') // Solid @fab('laravel') // Brands
当使用 @fa() 指令时,此包会扫描不同的 Font Awesome 库,并使用第一个找到图标的库。
库的扫描顺序为 regular、brands、solid。但可以在 配置 中修改此顺序。
参数
@fa() 函数可以接受三个参数,其中只有第一个是必需的。
| 参数 | 类型 | 描述 |
|---|---|---|
name |
string | 图标的名称 |
css_class |
string | 附加到svg输出中的额外CSS类 |
force_svg_href |
布尔值 | 如果可能,强制输出为svg href链接。在循环中可能很有用。 |
配置
该软件包包含一些配置选项,可以通过以下命令首先发布配置文件进行修改。这将创建一个位于您的config文件夹中的fontawesome.php文件。
php artisan vendor:publish --provider="Jerodev\LaraFontAwesome\FontAwesomeServiceProvider"
| 键 | 类型 | 默认值 | 描述 |
|---|---|---|---|
库 |
字符串数组 | ['regular', 'brands', 'solid'] |
将可用的图标库。这也是库搜索图标的顺序。 |
svg_href |
布尔值 | true |
对连续图标使用svg href链接。 |