1

I'm developing a custom laravel package for my needs, and discovered strange issue. My package is supposed to use custom helper function called t().

function t($string, array $options = [])
{
    // Function code goes here
}

It is located in my package folder, right near the package service provider. The service provider itself loads successfully, but helper file is not. I added following lines "autoload" section of the package's composer.json, just as I saw in other package:

"files": [
        "src/helpers.php"
    ]

then I dumped autoload. Everything works fine but this t() function. It's not found. What am I doing wrong?

P.S.: sure, I can include it in package service provider using require_once, but what is composer for either way?)

UPDATE package composer.json:

{
  "name": "astatroth/laravel-i18n",
   "require": {
     "astatroth/laravel-config": "^1.0"
    },
  "license": "MIT",
  "authors": [
    {
      "name": ".......",
      "email": "........"
    },
    {
      "name": ".......",
      "email": "........"
    }
  ],
  "autoload": {
    "psr-4": {
      "Astatroth\\LaravelI18n\\": "src/"
    },
    "files": [
      "src/helpers.php"
    ]
  },
  "minimum-stability": "dev"
}

Package file structure:

laravel-i18n
  config
  src
    I18nServiceProvider.php
    helpers.php
  composer.json
3
  • Make absolutely sure your path is correct. Commented Jun 8, 2017 at 7:33
  • It is correct. As it is in laravelcollective/html package: ` "autoload": { "psr-4": { "Collective\\Html\\": "src/" }, "files": [ "src/helpers.php" ] }` Commented Jun 8, 2017 at 7:42
  • Could you post your full composer.json file and file structure? Commented Jun 8, 2017 at 8:29

2 Answers 2

1

My package

Packages or libraries by design does not support Composer configuration files, in other words composer.json file from your package folder is never read.

To workaround this problem, use vcs type instead of package when requiring the sources.

Related:

Sign up to request clarification or add additional context in comments.

Comments

0

Please run composer update if you use repositories symlink for adding your package to laravel project. I had a same issue, running composer dump-autload doesn't work, because your vendor folder not updated with your new file. Hope this can solve your issue.

1 Comment

well that was not nice it installed like hundreds of laravel packages in a package...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.