php artisan make:provider HelperServiceProvider
app/Providers/HelperServiceProvider.php が自動生成されます
public function register()
{
// ここから追加
foreach (glob(app_path().'/Helpers/*.php') as $filename){
require_once($filename);
}
// ここまで追加
}
'providers' => [
...
...
// ここを追加
App\Providers\HelperServiceProvider::class ,
],
(ディレクトリ権限エラーが出る場合は実行してください。)
chmod 0777 bootstrap/cache
作成場所は app/Helpers/myhelper.php です。 myhelper は 好きな名前に変更してください。
if (!function_exists('myhelper')) {
/**
* 自作ヘルパー関数
*/
function myhelper( $arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null )
{
return 'test';
}
}