A package to easily make use of SVG icons in your Laravel Blade views. Originally "Blade SVG" by Adam Wathan.
Turn...
<!-- camera.svg -->
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 13a3 3 0 11-6 0 3 3 0 016 0z"/>
</svg>
Into...
<x-icon-camera class="w-6 h-6" />
Or into...
@svg('camera', 'w-6 h-6')
Looking for a specific icon? Try our icon search: https://blade-ui-kit.com/blade-icons#search
Join the Discord server: https://discord.gg/Vev5CyE
Blade Icons is a base package to make it easy for you to use SVG icons in your app. In addition, there's also quite some third party icon set packages. Thanks to the community for contributing these!
We're not accepting requests to build new icon packages ourselves but you can start building your own.
Install the package with composer:
composer require blade-ui-kit/blade-icons
Then, publish the configuration and uncomment the default
icon set:
php artisan vendor:publish --tag=blade-icons
Make sure that the path defined for this icon set exists. By default it's resources/svg
. Your SVG icons will need to be placed in this directory.
Please refer to the upgrade guide
when updating the library.
When working with Blade Icons, and third party icon sets in particularly, you'll often be working with large icon sets. This can slow down your app tremendously, especially when making use of Blade components. To solve this issue, Blade Icons ships with caching support. To enable icon caching you can run the following command:
php artisan icons:cache
This will create a blade-icons.php
file in bootstrap/cache
similar to the packages.php
cached file. It'll contain a manifest of all known sets and icons with their path locations.
Caching icons means you won't be able to add extra icons, change paths for icon sets or install/remove icon packages. To do so make sure you first clear the icons cache and cache after you've made these changes:
php artisan icons:clear
It's a good idea to add the icons:cache
command as part of your deployment pipeline and always cache icons in production.
Alternatively, you may choose to disable Blade components entirely.
Blade Icons support multiple sets. You can define these by passing a key/value combination in the blade-icons.php
config file's sets
setting:
<?php
return [
'sets' => [
'default' => [
'path' => 'resources/svg',
],
],
];
Feel free to add as many sets as you wish. Blade Icons ships with a default
set for your app which you may adjust to your liking.
If you wanted to add icons from a different directory in your app, say resources/images/svg
, you can set it like this:
<?php
return [
'sets' => [
'default' => [
'path' => 'resources/images/svg',
],
],
];
⚠️ Always make sure you're pointing to existing directories.
In addition to a single path, you may define multiple paths for a single set with the paths
option instead:
<?php
return [
'sets' => [
'default' => [
'paths' => [
'resources/images/icon-set',
'resources/images/other-icon-set',
],
],
],
];
This gives you the benefit from grouping icons from different paths under a single set where you can define the same prefix and default classes.
⚠️ When using multiple paths instead of one, Blade Icons will return the first icon it finds when an icon name is present in more than one path. Please ensure you use unique icon names when registering multiple paths if you want to retrieve the correct icon.
If you host your icons on an external filesystem storage you can set the disk
option for an icon set to a disk defined in your filesystems.php
config file. For example, you might store your icons on an AWS S3 bucket which is set in your filesystems.php
config file with a disk key of s3-icons
:
<?php
return [
'sets' => [
'default' => [
'path' => '/',
'disk' => 's3-icons',
],
],
];
And from now on our default set will pull the icons from the S3 bucket. Also notice we've adjusted the path to /
because we store our icons in the root directory of this S3 bucket. If you have several icon sets uploaded to the same disk you can set your paths accordingly:
<?php
return [
'sets' => [
'heroicons' => [
'path' => 'heroicons',
'disk' => 's3-icons',
'prefix' => 'heroicon',
],
'zondicons' => [
'path' => 'zondicons',
'disk' => 's3-icons',
'prefix' => 'zondicon',
],
],
];
If you want to provide a fallback icon when an icon cannot be found, you may define the fallback
option on a specific set:
<?php
return [
'sets' => [
'default' => [
'fallback' => 'cake',
],
],
];
Now when you try to resolve a non-existing icon for the default icon set, it'll return the rendered "cake" icon instead.
You can also provide a global fallback icon instead. This icon will be used when an icon cannot be found and the set doesn't have its own fallback icon defined. It can reference any icon from any registered icon set.
<?php
return [
'fallback' => 'heroicon-cake',
];
⚠️ There's one caveat when using fallback icons and that is that they don't work when using Blade Components. In this case, Laravel will throw an exception that the component cannot be found. If you want to make use of fallback icons please consider one of the other usages.
In the default icon set the icon
prefix will be applied to every icon, but you're free to adjust this in the blade-icons.php
config file:
<?php
return [
'sets' => [
'default' => [
'prefix' => 'icon',
],
],
];
Defining a prefix for every set is required and every prefix should be unique.
When referencing icons with the Blade directive or helper you can omit the prefix to reference icons from the default
set. When referencing icons from other sets, using the prefix is required.
When an icon in the default set has a name which collides with a prefix from a set then the icon from the default set is retrieved first.
Please note that it's best practice that your icons themselves do not have the prefix in their name. So if you have a prefix in your set called icon
and your icons are named icon-example.svg
you should rename them to example.svg
. Otherwise you can run into unexpected name resolving issues.
It's also important to note that icon prefixes cannot contain dashes (-
) as this is the delimiter which we use to split it from the rest of the icon name.
You can optionally define classes which will be applied to every icon by filling in the class
setting in your blade-icons.php
config file:
<?php
return [
'class' => 'icon icon-default',
];
If you don't want any classes to be applied by default then leave this as an empty string. Additionally, the same option is available in sets so you can set default classes on every set.
The sequence in which classes get applied is <global classes> <set classes> <explicit classes>
. You can always override this by passing an explicit class with your attributes. Component classes cannot be overridden.
You can also optionally define some attributes which will be added to every icon in the attributes
setting of your blade-icons.php
config file:
<?php
return [
'attributes' => [
'width' => 50,
'height' => 50,
],
];
This always needs to be an associative array. Additionally, the same option is available in sets so you can set default attributes on every set.
It is not possible to overwrite existing attributes on SVG icons. If you already have attributes defined on icons which you want to override, remove them first.
There are several ways of inserting icons into your Blade templates. We personally recommend using Blade components, but you can also make use of a Blade directive if you wish.
The easiest way to get started with using icons from sets are Blade components:
<x-icon-camera/>
Icons in subdirectories can be referenced using dot notation:
<x-icon-solid.camera/>
You can also pass classes to your icon components (default classes will be applied as well):
<x-icon-camera class="icon-lg"/>
Or any other attributes for that matter:
<x-icon-camera class="icon-lg" id="settings-icon" style="color: #555" data-baz/>
⚠️ Note that with Blade components, using a prefix is always required, even when referencing icons from the default set.
If you don't want to use the component syntax from above you can also make use of the default Icon
component that ships with Blade Icons. Simply pass the icon name through the $name
attribute:
<x-icon name="camera"/>
If you want to use a different name for this component instead you can customize the components.default
option in your blade-icons.php
config file:
<?php
return [
'components' => [
'default' => 'svg',
],
];
Then reference the default icon as follow:
<x-svg name="camera"/>
You can also completely disable this default component if you want by setting its name to null
:
<?php
return [
'components' => [
'default' => null,
],
];
Although they're enabled by default, if you don't wish to use components at all you may choose to disable them completely by setting the components.disabled
setting in your blade-icons.php
config file to true
:
<?php
return [
'components' => [
'disabled' => true,
],
];
Doing this makes sense when you're only using the directive or the helper and can improve overall performance.
If components aren't really your thing you can make use of the Blade directive instead. If you defined a default icon
class in your config and want to render a camera
icon with an icon-lg
class you can do that like so:
@svg('camera', 'icon-lg')
Any additionally attributes can be passed as a third array argument, and they'll be rendered on the svg
element:
@svg('camera', 'icon-lg', ['id' => 'settings-icon'])
If you don't have a class to be defined you can also pass these attributes as the second parameter:
@svg('camera', ['id' => 'settings-icon'])
If you want to override the default classes, pass in the class as an attribute:
@svg('camera', ['class' => 'icon-lg'])
Attributes without a key, are supported too:
@svg('camera', ['data-foo'])
If you'd like, you can use the svg
helper to expose a fluent syntax for setting SVG attributes:
{{ svg('camera')->id('settings-icon')->dataFoo('bar')->dataBaz() }}
If you're interested in building your own third party package to integrate an icon set, it's pretty easy to do so. We've created a template repo for you to get started with. You can find the getting started instructions in its readme.
If you want to learn how to create packages we can recommend these two excellent courses:
Make sure to load your SVGs from the register
method of your package's service provider. Provide the path to your SVGs and provide your own unique set name and component prefix:
use BladeUI\Icons\Factory;
public function register(): void
{
$this->callAfterResolving(Factory::class, function (Factory $factory) {
$factory->add('heroicons', [
'path' => __DIR__.'/../resources/svg',
'prefix' => 'heroicon',
]);
});
}
Now your icons can be referenced using a component, directive or helper:
<x-heroicon-o-bell/>
@svg('heroicon-o-bell')
{{ svg('heroicon-o-bell') }}
Don't forget to make blade-ui-kit/blade-icons
a requirement of your package's composer.json
.
Blade Icons also offers an easy way to generate icons for your packages. By defining a config file with predefined source and destination paths, you can make updating your icons a breeze.
First, start off by creating a generation.php
config file in the config
directory of your icon package. Next, you can define an array per icon set that you want to generate. Below is a full version of this file with explanation for every option. Only the source
and destination
options are required.
<?php
use Symfony\Component\Finder\SplFileInfo;
return [
[
// Define a source directory for the sets like a node_modules/ or vendor/ directory...
'source' => __DIR__.'/../node_modules/heroicons/outline',
// Define a destination directory for your icons. The below is a good default...
'destination' => __DIR__.'/../resources/svg',
// Strip an optional prefix from each source icon name...
'input-prefix' => 'o-',
// Set an optional prefix to applied to each destination icon name...
'output-prefix' => 'o-',
// Strip an optional suffix from each source icon name...
'input-suffix' => '-o',
// Set an optional suffix to applied to each destination icon name...
'output-suffix' => '-o',
// Enable "safe" mode which will prevent deletion of old icons...
'safe' => true,
// Call an optional callback to manipulate the icon with the pathname of the icon,
// the settings from above and the original icon file instance...
'after' => static function (string $icon, array $config, SplFileInfo $file) {
// ...
},
],
// More icon sets...
];
See an example config/generation.php
file for the Heroicons package.
After setting up your config file you can use the icon generation as follow from the root of your icon package directory:
vendor/bin/blade-icons-generate
Check out the CHANGELOG in this repository for all the recent changes.
Blade Icons is developed and maintained by Dries Vints.
Blade Icons is open-sourced software licensed under the MIT license.
不限制在view中使用PHP原生代码 @section 定义一个片段 @yield() 占位符 在 *.blade.php 中引用布局文件 @extends('layouts') layouts.blade.php 文件中代码 <!DOCTYPE html> <html> <head> <title>轻松学会laravel - @yield('title')</title> </head>
https://oblador.github.io/react-native-vector-icons/ 所谓的索引地址:就是我们通过name属性的时候填写的值 实际图片是什么样子的。
@extends('components.demo') 继承resources/views/components/demo.blade.php 的文件内容 @section('title', 'Page Title') 匹配父视图的的title属性,然后替换内容显示为 Page Title; 如果没有传第二个参数,就以 @endsection 结束,之间的内容为匹配要显示的内容 @endsec
Adaptive icons support a variety of visual effects. Android 8.0 (API level 26) introduces adaptive launcher icons, which can display a variety of shapes across different device models. Creating ada
Nacos Nacos Config 需要在 bootstrap.properties 中配置 Nacos server 的地址和应用名 之所以需要配置 spring.application.name ,是因为它是构成 Nacos 配置管理 dataId字段的一部分。 ${prefix}-${spring.profiles.active}.${file-extension} prefix 默认为
Blade是Laravel框架下使用的模板引擎,不同于我们原来所熟悉的smart等模板,blade是由模板继承与模板片段构成. 以下内容来自于:http://laravel-recipes.com/recipes/248/knowing-all-the-blade-template-commands {{ $var }} - Echo content {{ $var or 'default' }}
可构建目标 1. cc_library 2. cc_binary 3. cc_test 4. proto_library 5. lex_yacc_library 6. gen_rule 7. swig_library 8. cc_plugin 9. resource_library 10. java_jar 11. py_binary
blade模板简介 在之前的laravel的了解过程中,知道怎么去使用laravel中的blade模板,同时也了解到在laravel中blade模板引擎功能非常强大,在这里不限制开发人员使用原声php代码,并且会把编译后的php原生代码生成缓存文件,方便在调试错误的时候,直接查看,当然这些呢仅仅是它的一部分,laravel官方在应用blade的模板中声明了很多函数,可以在blade模板中灵活的去应
// 区块占位 @yield('name') // 扩展布局模板 @extends('layout.name') // 实现命名为 name 的区块(yield 占位的地方) @section('name') @stop // 可继承内容区块 @section('sidebar') @show // 继承父模板内容(@show 的区块内容) @parent // 包含子视图 @include('v
Blade 是一款追求简约、高效的 Web 框架,让 JavaWeb 开发如虎添翼,在性能与灵活性上同时兼顾。 功能特性 [x] 新一代MVC框架,不依赖更多的库 [x] 摆脱SSH的臃肿,模块化设计 [x] 源码不到 500kb ,学习也简单 [x] Restful风格路由设计 [x] 模板引擎支持,视图开发更灵活 [x] 高性能,100并发下qps 14w/s [x] 运行 JAR
Blade 是一款追求简约、高效的 Web 框架,让 JavaWeb 开发如虎添翼,在性能与灵活性上同时兼顾。 功能特性 [x] 新一代MVC框架,不依赖更多的库 [x] 摆脱SSH的臃肿,模块化设计 [x] 源码不到 500kb ,学习也简单 [x] Restful风格路由设计 [x] 模板引擎支持,视图开发更灵活 [x] 高性能,100并发下qps 14w/s [x] 运行 JAR
本书共有四个部分,九个章节,全面介绍如何基于 Blade 框架快速搭建一个 web 应用。 第一部分是快速上手和入门 Blade以及Web开发的基础知识,这部分在第一章; 第二部分讲解一个 Blade 应用的项目结构和核心概念,包含核心对象,数据库操作,模板引擎等。这部分内容在第二章至第六章; 第三部分手把手带大家实现一个在线图片社交的web应用,将前面讲解的 Blade 知识融会贯通,真正做一个
Welcome! This project is STILL A WORK IN PROGRESS and not yet production ready - but I appreciate you trying this out and giving feedback! Babel-Blade ⛸️ babel-blade is the collective name for the bab
用cocos2d实现切水果游戏的刀切屏幕效果。用户用手指在屏幕上划动,屏幕上会出现刀划破屏幕的刀痕。 [Code4App.com]