Loading a composer package into Laravel 5 - php

Solved: I've added the php and illuminate/support packages into my package composer.json file and it started working. I've got no idea why though so if someone could explain, I would really appreciate it.
"require": {
"php": ">=5.4.0",
"illuminate/support": "~5.0"
},
I've created a composer package for Laravel 5 which should generate models based on an existing database schema. However i'm unable to load it in.
I add my Command class into the app/Console/Kernel.php
'Iber\Generator\Commands\MakeModelsCommand'
But then I get the following error:
Class Iber\Generator\Commands\MakeModelsCommand does not exist
I'm really new to Laravel and I'm not sure why this is happening since composer generates the autoloader file just fine. I've created and added (into config/app.php) a Service Provider but that doesn't get resolved either. Not sure what I'm doing wrong.
Here's the package:
https://github.com/ignasbernotas/laravel-model-generator

Apparently adding the required attribute with the following packages solved the issue. I'm still not sure why.
"require": {
"php": ">=5.4.0",
"illuminate/support": "~5.0"
},

Related

Laravel use package in package

I'm developing a package in Laravel 5.5 where I need this package:
https://github.com/laracasts/PHP-Vars-To-Js-Transformer
The problem is that It's not registering for some reason. When I dd in the JavaScriptServiceProvider.php nothing happens. When I use the Javascript facade I get an error that it does not exists?!
My package composer.json file:
"require": {
"php" : "^7.0",
"illuminate/support": "~5.5.0",
"laracasts/utilities": "^3.0"
},
I use Laravel 5.5 so it should be registered by default (composer.json from laracasts package):
"extra": {
"laravel": {
"providers": [
"Laracasts\\Utilities\\JavaScript\\JavaScriptServiceProvider"
],
"aliases": {
"JavaScript": "Laracasts\\Utilities\\JavaScript\\JavaScriptFacade"
}
}
}
What am I doing wrong here?
I faced the same problem using different other packages in my own package.
Here are the steps that worked for me:
Add the required package as a dependency in your own package:
composer require laracasts/utilities
Update your package in the Laravel project (e.g. by incrementing the version number or by removing your package and reinstalling it.
composer update # in main Laravel project
Then you should see, that in the main Laravel project there is auto-discovery of your own package and the dependency to laracasts/utilities.
Let me know if this helped you or if I can give more assistance.
You need to following steps, to solve this issue :
Run the command in your packages directory :
composer require laracasts/utilities
Now use this in your package (on top of the file) whenever you want to use this dependency:
use Laracasts\Utilities\JavaScript\yourClassName

Missing 'Illuminate\Routing\ControllerServiceProvider' class on Laravel 5.2

I have updated the composer.json file as instructed on the upgrade guide on Laravel 5.2 Documentation and run composer update.
Everything was updated correctly, but composer dumped the error below while generating autoload files.
Class 'Illuminate\Routing\ControllerService Provider' not found in /home/vagrant/Code/homework/vendor/laravel/framework /src/Illuminate/Foundation/ProviderRepository.php on line 146
Make sure you remove Illuminate\Routing\ControllerServiceProvider from your /config/app.php.
https://www.laravel.com/docs/5.2/upgrade (see the "Service Providers" section)
Problem is with your composer.json.It may got corrupted. Make sure
"require": {
"laravel/framework": "5.2.*"
},
exists.Then run composer update.

Composer Laravel Class 'yajra\Datatables\DatatablesServiceProvider' not found

I have a problem with laravel and composer package yajra/laravel-datatables
Here is my require part from composer.json:
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"cartalyst/sentinel": "^2.0",
"laravelcollective/html": "^5.2",
"yajra/laravel-datatables-oracle": "^6.1"
},
After executing composer update all passes fine and I can check that inside vendor dir has appeared yajra folder.
After that I have add new provider in app.php:
yajra\Datatables\DatatablesServiceProvider::class
and then run php artisan but followingerror appears in the console:
Class 'yajra\Datatables\DatatablesServiceProvider' not found
I can fix this error by editing autoload_classmap.php file and manually add
'yajra\\Datatables\\DatatablesServiceProvider' => $vendorDir . '/yajra/laravel-datatables-oracle/src/DatatablesServiceProvider.php',
Anyway, the next time I execute composer update this line is deleted and again appears the same error and I again have to manually edit autoload_classmap.php file.
There is something wrong which causes composer update to not update relevant autoload files. I can not get it what is going on.
You should use in your app.php
Yajra\Datatables\DatatablesServiceProvider::class
instead of
yajra\Datatables\DatatablesServiceProvider::class
(with capital letter)
Try removing syntactic sugar operators like tilde and caret sign in composer.json. Because sometimes they do not allow the exact version to install. The same problem happened to me also. Then run,
comoposer update
Solved the issue for me.

Class 'ZendService\Amazon\S3' not found even though it is installed via Composer

My project is based on the Zend Skeleton App, and I'm using Composer to add vendor packages. However, when I add the zendservice-amazon package, it is not getting autoloaded.
Here is part of my composer.json file:
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.3.*",
"zendframework/zendservice-amazon": "2.0.*",
"doctrine/doctrine-orm-module": "0.7.*",
"zf-commons/zfc-user-doctrine-orm": "dev-master"
}
I have looked at the autoload files in the vendor directory, and they include the ZendService\Amazon namespace. I've tried several different things, but it's not working.
I've double checked that composer's autoloader is being used, so this is really puzzling. Any ideas? Thanks in advance.
The documentation and examples are wrong in the Zend Framework documentation. Instead of:
$s3 = new \ZendService\Amazon\S3();
You need to add an extra "S3":
$s3 = new \ZendService\Amazon\S3\S3();

Composer update PHP warning -- related to new package? (Laravel4)

I just added a new package to my composer.json in Laravel4 --
"barryvdh/laravel-dompdf": "0.4.*"
and on doing command line "composer update", I got this warning:
PHP Warning: Unexpected character in input: ' in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php on line 118
which I've never seen before on all previous Composer updates, which have all been flawless. In fact, the exact same message appeared 6 times, so I'm assuming that this reflects multiple attempts by Composer.
Here's my "require" array in composer.json:
"require": {
"laravel/framework": "4.2.*",
"barryvdh/laravel-dompdf": "0.4.*"
},
Am I correct in assuming that this relates to bad code in the package I've added, and not something on my end? The only change I made was to add the package to my composer.json file, and that's clearly not what the error message refers to. Thanks.
Take the package out of your composer file, and then do:
composer update
Then, add a different package, if you need an example: use Jefferey Way's laravel generator:
"way/generators": "2.*"
which every laravel install should have. if it runs through correctly, post an issue on the conflicted packages github about the error.
I apologize that i cant give you an exact answer, but unit testing the conflicting package is outside the scope of the question

Categories