laravel 5.5 package developing need to use composer require vendor_name/package_name - laravel

I developed a Laravel 5.5 package with package auto discovery and pushed it at git hub
https://github.com/adamibrahim/authconfirm
when i run
$ composer require "adamibrahim/authconfirm" : "v0.1.1"
I got an error
could not find package adamibrahim/authconfirm at any version for your min ...
do i need to register my repository somewhere so i can use composer require command ?
here is my package composer.json
{
"name": "adamibrahim/authconfirm",
"type": "library",
"description": ":Laravel 5.5 Auth modifications to confirm the auth email",
"keywords": [
"Laravel5.5",
"Auth",
],
"homepage": "https://github.com/adamibrahim/authconfirm",
"license": "MIT",
"authors": [
{
"name": ":Adam Ibrahim",
"email": ":adamibrahim1701#gmail.com",
"homepage": ":author_website",
"role": "Developer"
}
],
"require": {
"illuminate/support": "~5.1",
"php" : "~5.6|~7.0"
},
"require-dev": {
"phpunit/phpunit" : ">=5.4.3",
"squizlabs/php_codesniffer": "^2.3"
},
"autoload": {
"psr-4": {
"Adamibrahim\\Authconfirm\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Adamibrahim\\Authconfirm\\": "tests"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"sort-packages": true
}
}

Well, it's not enough just to create Github repository to use it via composer. You should create account at https://packagist.org/ and add your package in there to make it available via composer require.
In addition you should setup Packagist integration on Github at:
https://github.com/adamibrahim/authconfirm/settings/installations
to make sure after changes in Github Packagist will see those changes.

Related

How to install github package in laravel 7

I am new in laravel 7. i want ask how to install github package into my laravel project.
(https://github.com/lomotech/jajahan) this package i want to install to my laravel but not instruction in this package.
If a package is missing a composer.json, you can add the following to your project's composer.json:
"repositories": [
{
"type": "package",
"package": {
"name": "lomotech/jajahan",
"version": "v2.2018.01",
"source": {
"url": "https://github.com/lomotech/jajahan",
"type": "git",
"reference": "master"
}
}
}
],
"require": {
"lomotech/jajahan": "*"
},
"autoload": {
"psr-4": {
"Lomotech\\Jajahan\\": "vendor/lomotech/jajahan/"
}
},
The autoload entry allows composer to generate the vendor classmaps so you can use the package in your code by:
use Lomotech\Jajahan\SomeClassFile;
Finally, run composer install/update.

how to stop composer from removing manually installed package

For some reason I'm unable to install Predis package in my project via composer require predis/predis, I have manually downloaded Predis package from https://php-download.com and moved predis folder to the vendor and then updated files inside vendor/composer, it works fine.
However, the problem is when I run composer dump-autoload, this command removes all references of this package from vendor/composer/autoload_psr4.php and autoload_static.php files.
Can someone please help me how can I prevent composer dump-autoload to remove references of this package?
Instead of copying your package to the vendor directory, you can use "repositories" in install a local package:
{
"repositories": [
{
"type": "path",
"url": "../../packages/my-package"
}
],
"require": {
"my/package": "*"
}
}
I fixed it by adding following code in vendor/composer/installed.json , I forgot to add it.
{
"name": "predis/predis",
"version": "v1.1.1",
"version_normalized": "1.1.1.0",
"source": {
"type": "git",
"url": "https://github.com/nrk/predis.git",
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nrk/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"suggest": {
"ext-curl": "Allows access to Webdis when paired with phpiredis",
"ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
},
"time": "2016-06-16T16:22:20+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Predis\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Daniele Alessandri",
"email": "suppakilla#gmail.com",
"homepage": "http://clorophilla.net"
}
],
"description": "Flexible and feature-complete Redis client for PHP and HHVM",
"homepage": "http://github.com/nrk/predis",
"keywords": [
"nosql",
"predis",
"redis"
]
}

How to add a package to a custom laravel package?

I'm building a custom Laravel package which requires the guzzlehttp/guzzle package. Below is my composer.json file:
{
"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:
<?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.
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.
I had to push my code to a repo lomse/awesome-package on Github
then specified preferred-install as dist in the ./lomse/awesome-package/package.json config property`:
"config": {
"preferred-install": "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:
"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:
"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:
composer update -vvv
-vvv is for debugging purposes

composer outdated without install

I'd like to fetch the composer.lock (& .json) from a project, and run some test to see if there is outdated packages in it.
the composer outdated seems to require me to install all packages first,
but that seams a bit overkill, as all needed information should be in the composer.lock-file.
Is there information avaible after an install, thats not avaible from the lock-file?
Is it posible to find outdated packages without running the composer install?
Update 1
I take "foolz/sphinxql-query-builder" as an exemple from one project.
In composer.json there is a
require['foolz/sphinxql-query-builder'] = '^1.0'.
In composer.lock there is a
packages[] = {name: foolz/sphinxql-query-builder, version: '1.0.2', ...}
In ~/.cache/composer/repo/https---packagist.org/p-provider-2018-04.json there is a providers['foolz/sphinxql-query-builder']->sha256
In ~/.cache/composer/repo/https---packagist.org/provider-foolz\$sphinxql-query-builder.json there is a
packages['foolz/sphinxql-query-builder']->$version
From that file i can run
array_keys((array) $json->packages->{'foolz/sphinxql-query-builder'})
to get a list of availible versions.
So how do i fetch the latest 'provider-foolz\$sphinxql-query-builder.json' file?
Composer.lock defines the exact versions of your packages, so only with this file you are not able to define if it is possible to upgrade the package to a new tag version
For example,
In composer.json you have this version of package
"laravelium/sitemap": "^3.0",
In composer lock there exists this information
{
"name": "laravelium/sitemap",
"version": "v3.0.1",
"source": {
"type": "git",
"url": "https://gitlab.com/Laravelium/Sitemap.git",
"reference": "b287ec4a6b47dcd63fd121199c05e059c479bc6f"
},
"dist": {
"type": "zip",
"url": "https://gitlab.com/api/v4/projects/Laravelium%2FSitemap/repository/archive.zip?sha=b287ec4a6b47dcd63fd121199c05e059c479bc6f",
"reference": "b287ec4a6b47dcd63fd121199c05e059c479bc6f",
"shasum": ""
},
"require": {
"illuminate/support": "5.7.*",
"php": ">=7.1.3"
},
"require-dev": {
"orchestra/testbench": "3.7.*",
"phpunit/phpunit": "~7.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Laravelium\\Sitemap\\SitemapServiceProvider"
]
}
},
"autoload": {
"psr-0": {
"Laravelium\\Sitemap": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Roumen Damianoff",
"email": "roumen#damianoff.com",
"homepage": "https://damianoff.com",
"role": "Developer"
}
],
"description": "Laravelium Sitemap package for Laravel.",
"homepage": "https://laravelium.com",
"keywords": [
"Sitemap",
"generator",
"google-news",
"html",
"laravel",
"laravelium",
"php",
"xml"
],
"time": "2018-09-04T19:08:44+00:00"
},
Note, that you will install version v3.{\d+} (>=3 && <4) if it exists, and new tag version may have incompatible change
composer show -l returns the list of packages. Coloured red packages can be updated, and colored green are on the latest version.
Nevertheless, you steel need to proceed with composer install, because only this way you can understand the exact versions of installed packages

L5.5 : How to auto discover package?

I want to create package and I following this tutorial https://devdojo.com/blog/tutorials/how-to-create-a-laravel-package
I want to use auto discover the new feature of L5.5, how step-3 should be? (what I need to write on laravel's composer.json)
Laravel’s custom package’s providers will be auto-discovered only if the package present in vendor folder, So for that we need to make our package installable via composer itself.
So we need to make our custom package should be installable via composer, for that set your applications composer file with minimum-stability as dev is must and we have to configure custom packages path.
"minimum-stability" : "dev",
"repositories": [
{
"type": "path",
"url": "./packages/suresh/calc/"
}
]
once you done that your package can be installed using composer require <vendor/package>, then it will configure auto discover as per your packages settings. Get the sample configurations for your package,
{
"name": "suresh/calc",
"description": "This demo for auto discover providers in laravel with custom package",
"authors": [
{
"name": "Suresh Veluamy",
"email": "sureshamk#gmail.com"
}
],
"minimum-stability": "stable",
"require": {},
"autoload": {
"psr-4": {
"Suresh\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Suresh\\Calc\\CalcServiceProvider"
]
}
}
}
For more information, i wrote a post, check it out here

Resources