weirdo / laravel-easyblade
使用EasyBlade创建更简单、更易读的Blade视图
0.8
2023-05-01 14:43 UTC
Requires
- php: ^7.3|^8.0
- illuminate/support: ^5.7|^6.0|^7.0|^8.0|^9.0|^10
- laravel/framework: ^5.7|^6.0|^7.0|^8.0|^9.0|^10
Requires (Dev)
- orchestra/testbench: ~3.7|^4.0|^5.0|^6.0
This package is auto-updated.
Last update: 2024-09-30 01:46:58 UTC
README
您可以使用EasyBlade创建更简单、更易读的视图
安装
composer require weirdo/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">