rezaamini-ir / laravel-easyblade
使用 EasyBlade 创建更简单、更易读的 Blade 视图
1.0
2023-06-21 09:27 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
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">