Reputation: 11
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
Upvotes: 1
Views: 1695
Reputation: 1
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.
Upvotes: 0
Reputation: 166359
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:
autoload
in package doesn't generate classmap at GitHubUpvotes: 1