I just want to ask a question. I just want to ask if there's a way to include ServiceProviders in Laravel manually? I looked in github page and I saw some laravel serviceprovider. How can I include those in my laravel file? I am new to laravel and I am studying this in our home without an Internet connection. I downloaded the HTMLServiceProvideer manually and I also tried the command:
composer require illuminate/html
Can the composer run without having an Internet Connection? If no how can I install a serviceprovider by using the master-files? Where should I place the files and what file should I need to update?
I believe this is possible but you need to manually do the work of the Composer.
So for instance lets assume want to manually install illuminate/html package.
You can follow these steps:
Add "illuminate/html": "5.*" to your composer.json although we are not using Composer for installing this package, its important we have this listed in composer.json should in case we run 'composer update' in the future our manually added package will not be deleted but rather updated.
"require":{
"laravel/framework": "5.0.*",
"illuminate/html": "5.*"
}
Manually download the package from Github and place the package inside
vendor directory which is located at the root of your laravel application
example in mylaravelapp/vendor
Add the package to mylaravelapp/vendor/composer/autoload_namespaces.php
return array(
.....
'Illuminate\\Html\\' => array($vendorDir . '/illuminate/html'),
);
Add the package to mylaravelapp/vendor/composer/autoload_namespaces.php
return array(
....
'Illuminate\\Html\\' => array($vendorDir . '/illuminate/html'),
);
Run composer dump-autoload to check for errors
Add Package service provider in config/app.php 'providers' => []
Run composer dump-autoload once more
Service Providers are added to your config/app.php
But you will need to have that package downloaded...
Related
I want to use a library that's registered with composer in Magento 2 admin.
The library is
https://packagist.org/packages/flagshipcompany/flagship-api-sdk
I have a custom module that adds a button to admin order view and on the click of the button, the controller is called. I need to use this library in that controller.
I'm very new to composer and Magento. I'm not even sure if my composer.json is correct.
I have executed composer install in my module directory and I have the vendor directory.
The directory structure is
Magento2/app/code/MyCompany/MyModule/
Controller/Adminhtml/ControllerName/Index.php
etc/adminhtml/di.xml
etc/adminhtml/routes.xml
etc/module.xml
Plugin/....
composer.json
composer.lock
vendor/[all the composer generated directories]
I need to use require 'vendor/autoload.php' in Controller/Adminhtml/ControllerName/Index.php. But everytime I put this line of code, it crashes.
Also, once I am able to use autoload.php, I need to create an object of class Flagship which is present at vendor/flagshipcompany/flagship-api-sdk/Shipping/Flagship.
TIA
Composer is a php dependency manager and it can be used with Magento as well. Here are the steps to install composer and check composer.json:
First open the composer.json file and add the following code to use the "flagship-api-sdk" package:
"require": {
"php": ">=7.1.0",
"flagshipcompany/flagship-api-sdk": "",
"phpunit/phpunit": "^6.5",
"tightenco/collect": "^5.7"
}
Then go to the folder where you have installed Magento and using terminal/command prompt, run the following commands:
composer install
Make sure you are connected to the internet, this process will take 3-5 minutes.
After this you can check if the dependencies are installed using
composer show
P.s Make sure you have php version 7.1.0 or above and using Magento 2.2
I've added
"laravel/socialite": "~2.0"
as a composer dependency, and i've added the service provider in my config/app.php just like this
'providers' => [
// more providers
'Laravel\Socialite\SocialiteServiceProvider'
]
Then, when i access to any of my application route, i've got this Class 'Laravel\Socialite\SocialiteServiceProvider' not found exception.
Looking into my vendor/composer/autoload_psr4.php i see there's not the Socialite mapping - ive ran composer update and composer dump-autoload more than once.
What's wrong?
Did you run the composer command before adding the provider to the file? If not, this can sometimes cause issues.
I recommend removing the reference from the config file and the composer.json, then running composer request laravel/socialite 2.0. Also, just fyi, using the ::class notation in the providers listing will help if you're using a full IDE like phpstorm, as it will highlight when it can't find the class.
I have removed the reference from the config file and the composer.json, then ran composer require laravel/socialite 2.0 instead of composer request laravel/socialite 2.0.
Then add the following lines to the config file
Laravel\Socialite\SocialiteServiceProvider::class,
and
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
first of all remove the line
Laravel\Socialite\SocialiteServiceProvider::class,
and also
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
from Config\app.php and update the composer by adding
"laravel/socialite": "^2.0" and after that add these two line in Config\app.php it will work because when you add these lines before updating composer it goes to vender folder and search for the SocialiteProvider but it is not available yet so when you will update composer first and then add these lines it will work fine
At first of all, check if your socialite package is compatible with your Laravel version.
You can verify your Laravel version inside your Laravel path, for it type:
$ php artisan --version
Then, check in the socialite Git repository (link below) a compatible version with your Laravel.
https://github.com/laravel/socialite/releases
Now install the socialite package with composer require laravel/socialite x.x (where x.x is your socialite choosed version)
Lastly add the following lines in config/app.php file
inside 'providers' => [
Laravel\Socialite\SocialiteServiceProvider::class,
and almost at the end of the file, inside 'aliases' => [
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
Save the file.
first of all you need to clear the cache of your project by this code
php artisan config:cache
and then you need to enter this code in the terminal (for facebook for example)
composer require socialiteproviders/facebook
in the previous line i ended it with facebook as an example but you could change it like instagram or anything else and the error will be solved
I already know how to install by going through composer.json to add laravel/cashier, then composer update, and then add some line in app provider. But where does this folder go? What other things does it add in my app to make it fully functional? What is the work flow of composer update in Laravel 4?
Composer is a dependency management tool for PHP. It is not a typical package manager as it does not install libraries globally, but on a per project basis. It uses the file "composer.json" to install, update and remove libraries specified, including the version requested.
Composer creates an "autoload.php" file that, if included in your project, autoloads all libraries and classes and makes them available for use.
Typically, in a regular PHP project, you'd include the following line to bootstrap your project:
require 'vendor/autoload.php';
Now, when you execute composer install (for first time) or composer update (every time after), Composer adds/removes packages according to configuration made in "composer.json" file. All packages go in the directory "vendor" found in root of your project directory.
Laravel, by default, is a Composer project. You know when you execute composer create-project laravel/laravel my-app --prefer-dist to install Laravel, you are telling Composer to build a "composer.json" file with Laravel project and its dependencies, and run composer install. That's all!
Last but not least, Laravel, since it is a Composer project, includes "autoload.php" file and autoloads all packages within that project by default. You will notice "vendor" directory in the root directory. In Laravel 5 project, if you navigate to "bootstrap/autoload.php" file, you will see Laravel includes "autoload.php" file: require __DIR__.'/../vendor/autoload.php';
To answer your question about manually installing Laravel Cashier, Laravel Cashier is a package made specifically for Laravel, and as such, is not meant to be used on regular PHP project, unless you use specific classes and do some tweaking. To manually install Laravel Cashier, if you go to the following link, you will find link to "laravel/cashier" GitHub repository, from where you can manually download Zip file or clone the repository using git:
https://packagist.org/packages/laravel/cashier
I hope this adequately answers your questions - I kept it as simple as I could. Let me know if you have any other questions.
I am trying to execute a migration to rename some columns and I got an exception.
As I read on the documentation I have to add the doctrine/dbal dependency to my composer.json file. How do I do that? Which is the correct composer.json file. I have many in my application. Is the one that is on the same level as the folders app,bootstrap, public and vendor.
If so how do I add that dependency. Do I have to download anything?
By the way im using easyphp, not wamp!
Edit 1
After doing that the console throws this error
1) To install dependency , run this command
composer require doctrine/dbal
2) For 'git' is not recognized error, either you don't have git installed or the PATH is not added in the environment variables.
Install git for windows.
To add this dependency open the composer.json at the root of your project (in the same level as app, public etc.) and in the require section add the doctrine/dbal package like:
"require": {
"laravel/framework": "4.1.*",
"doctrine/dbal": "v2.4.2"
},
Save the file and run composer update
Edit
You probably installed git with the default settings and it's not in your PATH env.
Open Git Bash (it was installed with git - you will find it in your programs) and do composer update. By the way it's far better that windows command prompt.
If you are getting error while running migration try this
composer require doctrine/dbal:2.*
Scenario: I am working with Symfony 2.2. In my list of required packages is also one of my github repositories, let's call it "TestLib".
I know that I can define the github url as additional repository in Symfony's composer.json to download "TestLib" via Composer from Github.
Problem: I cannot commit to "TestLib" repository as there is no local .git directory in the "TestLib" directory. I guess composer is fetching a zip from Github and not cloning it.
So my question is: is there a way to specifiy in Symfony's composer.json that Composer should clone TestLib?
Question 2: Maybe my workflow is wrong - so if you also have this scenario - how do you handle this?
Adding #dev to the package version clones the repository too.
{
"require": {
'package': '*#dev'
}
}
Also is possible setup source as preference in the composer.json
{
"config": {
"preferred-install": "source"
}
}
What I typically do if I notice that a vendor has an issue is rm -rf vendor/foo/bar to remove it and then I run composer install --prefer-source to get it back as a git repo.
What I did was add my github repo to packagist.org then I did this:
composer require malhal/createdby dev-master --prefer-source
This appears to add the require line to composer.json and also get it as a git repo, unfortunately this only works once so if you wouldn't be able to reuse the composer.json for a new install and would need to delete the require line and then remember to do this same command again. This command also downloads the git repo you don't have to do another composer update.