tiagof2 / laravel-easyblade
使用 EasyBlade 创建更简单、更易读的 Blade 视图 [分支]
v0.7.1
2024-02-23 23:02 UTC
Requires
- php: ^7.3|^8.0
- illuminate/support: ^8.0|^9.0|^10.0
- laravel/framework: ^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0
This package is auto-updated.
Last update: 2024-09-24 16:09:41 UTC
README
laravel EasyBlade
您可以使用 EasyBlade 创建更简单、更易读的视图
安装
composer require rezaamini-ir/laravel-easyblade
用法
使用 EasyBlade,正如其名,非常简单!
想象一下,您想在 Blade 中的 href 写一个路由 URL,您将不得不编写以下代码
<a href="{{ route('home') }}"></a>
但通过使用 EasyBlade,只需写
<a href="@route('home')"></a>
并且不要使用 "{{ }}" 或任何纯 PHP 代码
Blade 模板引擎并不是为纯 PHP 代码而创建的,而是为了编写更简单的代码。您可以通过 EasyBlade 传递它
当前指令
@asset('foo')
@url('foo')
@route('foo')
@isActive('routeName', 'active', 'deactive')
@count(array|collection, number )
@user(attr)
@sessionExists('name')
@session('name')
@image('address', 'cssClasses')
@style('style.css')
@script('script.js')
@config('app.name', 'Laravel')
@old('name', 'Reza')
功能
- 您可以将路由名称或路由名称数组作为第一个参数传递给
@isActive
指令,第二个参数是您想在视图中输出的字符串,第三个参数是可选参数,如果没有传递任何内容,它将返回空字符串,当当前路由不等于作为第一个参数传递的数组或字符串时将显示 - 您可以使用
@count
指令代替编写大量 if 语句来检查集合或数组中的计数是否等于或大于您传递给第二个参数的数字。
示例
@count
@count([1, 2, 3], 3) something @endcount // return `something` because count of array is equal 3
@count([1, 2], 3) true @endcount // return null because count of array is smaler than 3
@isActive
假设当前路由是:dashboard.home
@isActive('dashboard.home', 'active', 'deactive') // Return : active
@isActive(['dashboard.home', 'dahboard.profile'], 'active', 'deactive') // Return : active
@isActive('home', 'active', 'deactive') // Return : deactive
@asset
@asset('img/header.png') // Return : http://127.0.0.1/img/header.png (Like asset() helper )
@route
@route('dashboard') // Return : http://127.0.0.1/dashboard (Like route('routeName') helper )
@url
@url('/home') // Return : http://127.0.0.1/home (Like url('address') helper )
@user
@user('name') // It will run auth()->user()->name and return user's name // You don't need to check user is authenticated or not , it will check by itself
@sessionExists
@sessionExists('foo') Session Exists @endsessionExists // It will run session()->exists('foo') in a condition
@session
@session('name') // First it will check session exists then it will print value of session
@image
@image('img/img1.png', 'img-fuild rounded-circle') // Return a img tag with http://domain/img/img1.png file and 'img-fuild rounded-circle' class
@old
@old('name', $user->name) // Return something like : {{ old('name', $user->name) }}
@script
@script('/js/script.js') // Return script tag : <script src="/js/script.js"></script> @script('/js/script.js', true) // Second and third parameter is optional // Return script tag with defer : <script src="/js/script.js" defer></script>
@style
@style('/css/app.css') // Return link tag : <link rel="stylesheet" href="/css/app.css">
在 composer.json
中使用此 GIT 仓库
v0.6.x
与 Laravelv10.x
兼容。尚未在版本 11.x 中进行测试,但应该可以正常工作
// .. "license": "MIT", "repositories": [ { "type": "package", "package": { "name": "rezaamini-ir/laravel-easyblade", "version": "dev-tiagof2/v0.6.x", "source": { "type": "git", "reference": "tiagof2/v0.6.x", // Nome da branch a usar "url": "https://github.com/tiagofrancafernandes/laravel-easyblade" } } } ], "require": { // ... "rezaamini-ir/laravel-easyblade": "dev-tiagof2/v0.6.x", // HERE // ... }, // ... "config": { "optimize-autoloader": true, "preferred-install": "dist", // ... }, "minimum-stability": "dev", "prefer-stable": true // ...