我有一个自定义包没有上传到github
或packagist
上,我需要将其添加到Laravel 5.1
项目中。
这是我的包文件夹结构:
Packages
_ christian
_ smsservice
_src
_ Facades
_ MySMS.php
_ SMSServiceServiceProvider.php
_ vendor
_ composer
_ autoload.php
我已经编辑了我的根composer.json来添加包:
"psr-4": {
"App\": "app/",
"Christian\SMSService\": "app/Packages/christian/smsservice/src/"
},
然后,我将s ervice provider
和facade
添加到app.php
文件中,但当我尝试使用包时,我得到了:
FatalErrorException in ProviderRepository.php line 146:
Class 'ChristianSMSServiceSMSServiceServiceProvider' not found
但是ServiceProvider存在并且名称空间是正确的:
namespace ChristianSMSService;
use IlluminateSupportServiceProvider;
use IlluminateRoutingRouter;
class SMSServiceServiceProvider extends ServiceProvider {
//Code
}
我也需要这个功能。我正在为我当地的一个Laravel项目使用以下代码:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"repositories": [
{
"type": "path",
"url": "../../GitHub/laravel-page-visits-counter"
}
],
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"cyrildewit/laravel-page-visits-counter": "dev-master"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r "file_exists('.env') || copy('.env.example', '.env');""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\Foundation\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\Foundation\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}