繁体   English   中英

如何在Laravel中注册类似于Application.php中的自定义方法

[英]How do you register custom methods like those within Application.php in Laravel

我想知道如何在其中注册自定义方法:

Illuminate/Foundation/Application.php

喜欢:

/**
 * Get the current application name.
 *
 * @return string
 */
public function getName()
{
    return $this['config']->get('app.name');
}

取自:

/**
 * Get the current application locale.
 *
 * @return string
 */
public function getLocale()
{
    return $this['config']->get('app.locale');
}

我应该放在哪里,而不是供应商文件ofc?

谢谢

您也许可以扩展Illuminate/Foundation/Application.php

例:

 <?php 

 namespace app\Custom;

 class Application extends \Illuminate\Foundation\Application
 {

 }

有关更多详细信息,请单击此处。

注意:在供应商文件下添加代码,在composer update命令期间可能会丢失。 因此,不建议在此处实际添加自定义代码。

暂无
暂无

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

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