[英]How to add a package to a custom laravel package?
I'm building a custom Laravel package which requires the guzzlehttp/guzzle
package.我正在构建一个需要
guzzlehttp/guzzle
guzzle 包的自定义 Laravel 包。 Below is my composer.json file:下面是我的 composer.json 文件:
{
"name": "lomse/awesomePackage",
"description": "this an awesome package",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Selom",
"email": "awesome@gmail.com"
}
],
"minimum-stability": "dev",
"require": {
"guzzlehttp/guzzle": "^6.3"
},
"autoload": {
"psr-4": {
"Lomse\\AwesomePackage\\": "src/"
}
}
}
Below is the content of my AwesomeProvider.php
file:下面是我的
AwesomeProvider.php
文件的内容:
<?php
namespace Lomse\AwesomePackage;
use GuzzleHttp\Client;
use Illuminate\Support\ServiceProvider;
class AwesomeProvider extends ServiceProvider
{
public function boot(){
}
public function register()
{
$this->app->singleton(Awesome::class, function ($app) {
return new Awesome(new Client); //Class 'GuzzleHttp\Client' not found
});
}
}
I keep getting Class 'GuzzleHttp\\Client' not found
.我不断收到
Class 'GuzzleHttp\\Client' not found
。 What am I doing wrong?我究竟做错了什么?
So, this turns out to be quite simple.所以,这很简单。 I highlighted the steps to take in order to solve this.
我强调了解决这个问题要采取的步骤。 Hope this helps anyone who is having the same issue.
希望这可以帮助任何遇到相同问题的人。
lomse/awesome-package
on Githublomse/awesome-package
then specified preferred-install
as dist
in the ./lomse/awesome-package/package.json
config property`:然后在
./lomse/awesome-package/package.json
配置属性./lomse/awesome-package/package.json
preferred-install
指定为dist
:
"config": { "preferred-install": "dist" } “配置”:{“首选安装”:“dist”}
The full code is完整的代码是
{
"name": "lomse/awesome-package",
"description": "this an awesome package",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Selom",
"email": "awesome@gmail.com"
}
],
"minimum-stability": "dev",
"require": {
"guzzlehttp/guzzle": "^6.3"
},
"autoload": {
"psr-4": {
"Lomse\\AwesomePackage\\": "src/"
}
},
"config": {
"preferred-install": "dist"
}
}
In the root package.json
, specify the repository of your package as follow:在根
package.json
,指定包的存储库,如下所示:
"repositories": [
{
"type": "git",
"url": "git@github.com:lomse/awesome-package.git"
}
]
Also add your package repo to the package.json require
property as shown below:还将您的包存储库添加到 package.json
require
属性,如下所示:
"lomse/awesome-package": "dev-master"
From your root directory, run the code below to update your dependencies.从您的根目录运行以下代码以更新您的依赖项。 This will clone the
lomse/awesome-package
repo into your vendor folder and install any other dependencies required by your package:这会将
lomse/awesome-package
到您的供应商文件夹中,并安装您的包所需的任何其他依赖项:
composer update -vvv
-vvv
is for debugging purposes -vvv
用于调试目的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.