laravelで自作の関数を作る
自作関数を記述するファイルを作成
好きな所に自作関数を記述するファイルを作成。
app/functions.php
<?php// テスト関数if (!function_exists('test')) {function test($date = null) {return 'testです!';}}
オートローダーに追加
composer.json の autoload.files に追加
composer.json
"autoload": {"files": ["app/functions.php" //追加],
オートローダーの更新
$ composer dump-autoload
テスト
$ php artisan tinker> test()= "testです!"
呼び出し方
以下だけでコントローラーやbladeから自作関数を呼び出せるようになる。
test()


1件のコメントがあります