1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

laravel10での独自ヘルパ関数

Last updated at Posted at 2024-03-15

Geminiや検索で色々ヘルパー関数を独自で作るにはどうすればいいか調べていたが、composer.jsonの編集無し、AppServiceProvider.phpの編集もせずに割と簡単に行くことがわかったので誰かの役に立つかもしれないので書いておく

  • appフォルダの中にHelperフォルダを作る
  • その中にファイルを作る(ここではhelper.php)

helper.php

namespace App\Helpers;

function sayHello(){
    echo 'Hello World!';
}

これをviewやcontrollerファイルで呼び出す際は名前空間とともに記載すれば作動した

App\Helpers\sayHello()

これで動く

相当時間掛かって調べていたが、composer.jsonを編集する必要無いのが楽

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?