aminireza-ir/laravel-easyblade

此包已被弃用且不再维护。作者建议使用 rezaamini-ir/laravel-easyblade 包。

使用 EasyBlade 创建更简单易读的 Blade 视图

v0.1.7 2020-10-27 13:37 UTC

This package is auto-updated.

Last update: 2020-10-29 09:25:30 UTC


README

您可以使用 EasyBlade 创建更简单易读的视图

安装

composer require aminireza-ir/laravel-easyblade

使用方法

使用 EasyBlade 非常简单,正如其名。

想象一下,您想在 Blade 中编写一个路由 URL 的 href。您可以编写如下代码:

    <a href="{{ route('home') }}"></a>

但我们通过 EasyBlade 创建了一种更简单的方法,只需写

    <a href="@route('home')"></a>

并且在您的 blade 中不需要任何 {{ }},也不需要使用任何 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')

特性

  • 您可以将路由名称或路由名称数组作为第一个参数传递给 @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