czim/with-blade-directive

此包已被废弃,不再维护。未建议替代包。

@with blade directive

1.1.0 2016-09-27 19:09 UTC

This package is auto-updated.

Last update: 2021-05-19 21:44:57 UTC


README

Software License

这是一个简单的blade指令,用于帮助清理视图。

而不是这样做复杂的舞蹈

    <tr>
        <td>{{ $model->relation->method()->object->first_name }}</td>
        <td>{{ $model->relation->method()->object->first_name }}</td>
        <td>{{ $model->relation->method()->object->email }}</td>
    </tr>

你可以这样清理

    @with($model->relation->method()->object as $object)

    <tr>
        <td>{{ $object->first_name }}</td>
        <td>{{ $object->first_name }}</td>
        <td>{{ $object->email }}</td>
    </tr>

它所做的只是将一个表达式赋给一个变量。

安装

通过Composer

$ composer require czim/with-blade-directive

然后在 config/app.php 中添加服务提供者

Czim\WithBladeDirective\WithBladeDirectiveServiceProvider::class,

使用方法

@with 指令支持两种格式

    @with(any_expression($you * $want) as $variableName)

    @with('variableName', any_expression($you * $want))

这些有完全相同的结果。

鸣谢

许可

MIT许可(MIT)。请参阅许可文件以获取更多信息。