> For the complete documentation index, see [llms.txt](https://liseen315.gitbook.io/laravel/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://liseen315.gitbook.io/laravel/blade-mo-ban-yin-qing/zi-ding-yi-blade-zhi-ling/geng-jian-dan-de-if-yu-ju-zi-ding-yi-zhi-ling.md).

# 更简单的if语句自定义指令

虽然Blade指令功能强大,但是通常都用在if语句上,所以有一种更简单的方法创建自定义if指令Blade::if(),示例4-33显示了如何用Blade::if()重构示例4-32

{% code title="Example 4-33. Defining a custom “if ” Blade directive" %}

```php
// Binding
Blade::if('ifPublic', function () { 
    return (app('context'))->isPublic();
});
```

{% endcode %}

您可以以完全相同的方式使用这些指令，但是正如您所看到的，这更简单一些。不必手动键入php大括号，只需编写一个返回布尔值的闭包。
