Trying to install packages in Laravel 5 - composer-php

I was trying to install the package of HOA/Websockets in my Laravel 5 website,
from following link
https://laracasts.com/discuss/channels/tips/hoawebsocket-with-laravel-5-projects-push-notifications
But when I added the
"require": {
"hoa/websocket": "~2.0"
}
In my composer and ran
composer install
But in my command prompt it says nothing to be installed. Can any one help me out with this, Please?
Also when I try to do
composer require "hoa/websocket": "~2.0"
it is uninstalling some of the packages and not installing it back.

Well I fixed it this way
Just copied the new package that was installed inside the Vendor folder which was vendors/HOA,
Then I pasted in my older backup of the vendor folder and pasted it back inside my website and VOILA!! it works
Hope it helps some one needy
Thanks

Related

Autoload doesn't locate previous packages

I am learning to use composer and I am constantly stopping at one problem. I've tried to find the solution, without success...
When I install new packages into my vendor folder, where I already have packages installed, the new autoload.php + composer folder doesn't locate my previous packages anymore. However, my composer.lock still display all the packages.
Did I do something wrong? I used
composer require package/name
to add my new packages.
Thank you in advance for your help!
Problem solved:
Autoload psr-4 wouldn't work.
After manually adding the code into autoload_psr4.php and autoload_classic.php everything works.
My issue also was that one of my packages didn't exist anymore (FormGuide/PHPFormValidator), which made that I couldn't simple re-install everything.

How can I check what version of laravel-query-builder am I using?

An important security release for laravel-query-builder was launched.
Since I use it in my project, I want to check what version I am using. But I couldn't find it. I already searched in my composer.json file. Laravel version that is being used is "laravel/framework": "5.8.*".
Where is it located?
To check if this package is installed in your installation, type in your terminal:
composer show
It will show all your installed packages.
If you not installed this package with the command:
composer require spatie/laravel-query-builder
That package will not exist in your Laravel folder, because it's not a default package. And you do not have to worry.
Execute composer info | grep laravel-query-builder on your project root folder.
That will give you your installed version of the package, if the output is empty you don't have it installed.

Installing Composer and Packagers - first time

I have never used Composer, but I want to use PHPSpreadsheet package, and it is recommended that Composer is used.
I am on a MAC using XAMPP and Netbeans.
I have installed Composer, and I have run the following command to get and install the PHPSpreadsheet package.
php ../../Composer/composer.phar require phpoffice/phpspreadsheet
I am running this in my project folder, (hence the ../../ to where Composer.phar is located.
This downloads the files into a vendor folder in my project folder.
What should I do then? Do I need to keep it in the Vendor folder, or can I move into a folder of my choice?
Netbeans has Composer options in the menus, but as far as I can see, this is for creating dependencies rather than installing packages.
I know I am totally missing the point of Composer somewhere, but have spent hours just trying to get this work.
Many thanks
You should really start with the docs -> https://getcomposer.org/doc/01-basic-usage.md
You have to keep the vendor directory - this is where all dependencies are kept. If you require more packages - then they will be installed in that directory.
After requring the package you have to load it so the PHP will know all the classes. Composer comes with great autolader. It is located by default in vendor/autoload.php. So what you have to do now is to require this file in your project. After that all classes from composer packages will be loaded automaticaly each time you use them in the code :)
I hope this will help you with this great tool. Cheers.

Class 'Stripe\Stripe' not found error in PHP

I installed laravel and composer and created my first project in laravel. I want to integrate stripe using PHP. When I try to execute my first project in localhost I take this message:
Fatal error: Class 'Stripe\Stripe' not found in C:\xampp\htdocs\laravel\stripe\public\elda.php on line 21
To include the stripe libraries, I inserted inside the composer.json file the code from the API library for PHP. Here is an image of my composer.json file:
I run composer install in cmd and this is the output:
You may be getting outdated dependencies. Run update to update them.
I run composer update and the output is the error in the image below:
Can someone help me to solve this error?
Well, sorry did not make a comment of your post, but I have not enough points to do so. But you need to run composer install in the terminal after that includes a new package.
I had the same issue, but when I ran this command my issue is resolved.
composer require stripe/stripe-php
I hope this may help you, after you update your composer.

Installing only new packages from composer.json

I'm trying to make composer update only newly added packages to composer.json i.e when I manually add a package dependency to the composer.json file, it should update the composer.lock file only for the new package; the rest of the packages should be at the same version as before. I tried running composer update --lock but I don't think it does what I'm trying to achieve and it took a lot of time to finish. I checked the commands on composer's documentation but can't find one to achieve my wish. Any advice or workaround will be appreciated.
Note: I'm using Laravel Forge, so there is a 2 minutes deployment limit.
In order to install only new packages with composer you should run
composer install
Because composer update will install your new packages but will update and all the other already installed packages.
You can specify the name of the package as an argument to the update command. This will perform a partial update: composer update the-package/you-want-to-update
I think your question is related to your (guessed) current workflow: To add a new package you edit the composer.json file and then run composer update - wishing to only add/update that new file.
If that is true, here is the solution:
composer require new/package will add the newest possible version (taking into account the currently installed packages) of the new package. Benefits: Only one command line, and no fiddling with JSON content.
If you already know which version you want, you could also run composer require new/package:^2.1.25#beta (or whatever version and stability level you want - this example is exaggerating a bit). If this version is incompatible with existing packages, nothing will get installed, everything will get rolled back, and you get an error message.

Resources