Skip to content

Instantly share code, notes, and snippets.

@codeitlikemiley
Last active June 8, 2019 06:02
Show Gist options
  • Select an option

  • Save codeitlikemiley/d5a32288dc0ad77271ff9ed5d4d5a46c to your computer and use it in GitHub Desktop.

Select an option

Save codeitlikemiley/d5a32288dc0ad77271ff9ed5d4d5a46c to your computer and use it in GitHub Desktop.
Manage Composer Packages in laravel
use Nadar\PhpComposerReader\ComposerReader;
use Nadar\PhpComposerReader\RequireSection;
// Instantiate ComposerReader
$reader = new ComposerReader(base_path('composer.json'));
// Instantiate RequireSection
$section = new RequireSection($reader);
// get current content of require section in composer.json
$packages = $reader->contentSection('require',$section)
// packages to be added
$new_packages = ['beyondcode/laravel-websockets' => '^1.1'];
// merge to new array
$packages = array_merge($packages,$new_packages);
// update the require section in composer.json
$reader->updateSection('require', $packages);
// check if the reader instance has the new updated section
$reader->getContent();
// finally save it
$reader->save();
composer require nadar/php-composer-reader
diff --git a/composer.json b/composer.json
index 8e2b2d7..e3084ee 100644
--- a/composer.json
+++ b/composer.json
@@ -11,7 +11,8 @@
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
- "laravel/tinker": "^1.0"
+ "laravel/tinker": "^1.0",
+ "beyondcode/laravel-websockets": "^1.1"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
@@ -59,4 +60,4 @@
"@php artisan key:generate --ansi"
]
}
-}
+}
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment