简体   繁体   English

Laravel:助手功能会起作用吗?

[英]Laravel: Will Helper functions work for it?

I am using Multiple code blocks of Mail:: and Gate::define() in my code. 我在代码中使用Mail::Gate::define()多个代码块。 I rather want to make it as functions and call them. 我宁愿将其作为函数并调用它们。 What approach would be useful? 哪种方法有用? Should I create helper classes? 我应该创建助手类吗?

If You have some logic and you want to use this logic from many places, you must to encapsulate it, an in your situation it's not bad solution to create helper function or maybe helper class. 如果您有某种逻辑,并且想在许多地方使用此逻辑,则必须对其进行封装,在您的情况下,创建助手函数或助手类并不是一个坏办法。

If You don't know how - here is very clear example to do it : 如果您不知道如何-这是一个非常清晰的示例:

Creating a Helpers File 创建一个助手文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM