LoginSignup
13
12

More than 5 years have passed since last update.

laravel4 helper関数の追加

Last updated at Posted at 2014-07-09

専用のhelper関数を作りたい

composer.jsonの編集

composer.json
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php",
            "app/extensions"
        ],
        "files": [ // <- 追加
            "app/helpers.php" // <- 追加
        ] // <- 追加

dump-autoloadを実行

%composer dump-autoload

app/にhelpers.phpを作成

app/helpers.php
<?php

function temp_path()
{
    return storage_path() . '/temp';
}

function backup_path()
{
    return storage_path() . '/backup';
}

function restore_path()
{
    return storage_path() . '/restore';
}

確認

app/views/index.blade.php

{{backup_path()}}

表示された。

OK

13
12
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
13
12