ServiceProvider not found Laravel 5.0 - php

I'm trying to create a custom package for Laravel 5.0 based on this tutorials
The folder structure and service providers are exactly same, but some how the Serviceprovider is not updating autoload_namespace.php.
I already added my service provider in app/config.php
'Walkswithme\Users\UsersServiceProvider',
In my root composer.json I have following code.
"psr-4": {
"App\\": "app/",
"Walkswithme\\Users\\": "packages/walkswithme/users/src"
}
Under my packages folder files struture is as follows.
walkswithme
users
src
models
controllers
views
UsersServiceProvider.php
routes.php
composer.json
I can't use Laravel 5.1 it requires php 5.5.9 , Other wise I can user artisan packager command.
The error is getting is as follows.
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Walkswithme\Users\UsersServiceProvider' not found
Any help will be appreciated last 3hrs I'm digging on it.

I solved it myself ,
I tried composer dumpautoload -o so it works for me.
Also some time needs composer clearcache too.
Hope it helps someone else..

For me it was
Class 'Jubeki\LaravelCodeStyle\ServiceProvider' not found
And I just run
composer require jubeki/laravel-code-style --dev
In another folder (not where my common composer.json is located)
Maybe it also can help someone :)
Just check the place of the new bundle installation folder.

Related

PHP framework AMPHP/THREAD used with SYMFONY - Where does it have to be installed?

I am looking to implement the framework amphp/thread, with Symfony3, which I ve read about in this article (https://www.mullie.eu/parallel-processing-multi-tasking-php/).
I'd looked at the setting process on the git page: https://github.com/amphp/thread.
I've followed the checklist:
PHP5.5+ = OK Php 5.5.12
pecl/pthread = OK I did install it as explained on Windows8
Now, 3rd task on the checklist, I have the installation of the framework itself (amphp/thread) left to do.
I am a bit confuse, because it is not an "official" Symfony bundle. So I don't think I can put it under [my_symfony_project]/vendor/ and refer to it in the file [my_symfony_project]/app/AppKernel.php. So how do one do in this case:
Do one put the directory of the library under the root directory [my_symfony_project]?
And afterwards, how can one refer to it in the Symphony class/file, should I write: "use amphp/thread" between the namespace declaration of my Symfony file and the class code itself?
You can simply install the library with composer, as example launching this command from the root of your project:
>php composer.phar require amphp/thread
And use it in your code directly: the composer process generate the correct autoloader for you. No necessary add to the list of the Symfony2 bundle (is not a bundle).
Hope this help
You will need to install the package by adding the following to your composer.json file:
"require": {
"amphp/thread": "0.8.1"
}
Then run "composer install" on your server.

Publishing config and migrations from included package in Laravel

I'm using Laravel to build a package which will include some Admin functionality and will include some other packages.
I have included a package which has migrations and a config file, But how do I copy those to the correct folder in Laravel. The package has it's own ServiceProvider but How do I call that from my package?
I'm using the following to register the package in my package.
class CldServiceProvider extends ServiceProvider {
public function register()
{
$this->app->register(MediaLibraryServiceProvider::class);
}
}
I've tried
php artisan vendor:publish
But it says there's nothing to publish. Because it's only looking at the packages for this Laravel installation, and not the nested packages.
In my case I found I needed to include MY package in the application I was working on. This step was not included in the original tutorial I followed.
So in composer.json in the main app:
"repositories": [
{
"type": "path",
"url": "packages/namespace/name",
"options": {
"symlink": true
}
}
],
"require": {
// ...
"namespace/name": "dev-master"
},
And then we run this command from main folder:
composer update
After that running php artisan vendor:publish will include the option to publish the sub packages.
NB: The source for this info is: https://laraveldaily.com/how-to-create-a-laravel-5-package-in-10-easy-steps/
Try to publish the config separately and use the force switch
php artisan vendor:publish --tag=config --force
As #scrubmx mentioned, you need to include the code that defines what can be published, though this code shouldn't really be in your own service provider, but rather the other package you're including. If it doesn't seem to have this code, it's best to list it as an issue on that package's repository or create a pull request to add it.
Create database/migrations folder in your package root folder. Then add publish details in boot method in your service provider.
final class MyPackageServiceProvider extends BaseServiceProvider
{
public function boot(): void
{
$this->publishes([
__DIR__ . '/../database/migrations/' => database_path('migrations/my-package'),
], 'my-package-migrations');
}
}
Second part could be like database_path('migrations') or database_path('migrations/my-package'). I advise using with subfolder because if there are many packages migrations folder grows too much.
The part of 'my-package-migrations' is our tag. And run publish command with tag.
php artisan vendor:publish --tag=my-package-migrations
If you are using the subfolder php artisan migrate command won't work because we need to specify to exact migration folder like this,
php artisan migrate --path=/database/migrations/my-package
Yes, this looks a little bit dirty but organizes cables. And don't forget the using composer dump-autoload. If the service provider is registered this solution works. Also, you can use this method for config but config folder does not support subfolders.
I think you have publish the config files yourself
$this->publishes([
'other-package/absolute/path/some-config.php' => config_path('my-package.php'),
]);
Solution
I included the /packages/ folder in my current project where I was working on.
The problem is that when including the package in my composer.json
It is now reachable from 2 places inside my project, in the vendor folder and in my packages folder. This was causing issue's
I moved my packages outside my current project, this fixed the problem.
Publish vendor migration :
php artisan vendor:publish --tag=migration
Publish vendor config :
php artisan vendor:publish --tag=config

Class 'Codesleeve\LaravelStapler\Providers\L5ServiceProvider' not found when installing

I'm using LaravelStapler package to manage image in Laravel 5.1.
I installed LaravelStapler with the following steps:
Add "codesleeve/laravel-stapler": "^1.0" into composer.json file
Add 'Codesleeve\LaravelStapler\Providers\L5ServiceProvider' into providers array in config/app.php file
Run composer install
And faced the error:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Codesleeve\LaravelStapler\Providers\L5ServiceProvider' not found
If i run composer install before add 'Codesleeve\LaravelStapler\Providers\L5ServiceProvider' into providers array in config/app.php file, no error occurs.
It's hard for me to deploy into productions when I need to comment out 'Codesleeve\LaravelStapler\Providers\L5ServiceProvider' before composer install and uncomment after in production.
Are there any solutions which I can install it without commenting out 'Codesleeve\LaravelStapler\Providers\L5ServiceProvider' ?
Thanks in advance !
Update:
Sorry, It's my mistake. My team mate ignored composer.lock in Repository. I reviewed his pull-request and didn't realize that. Everything works as normal.

Manually attach package to Laravel (unable to use composer due to firewall)

I can't use composer to handle my dependencies due to the corporate firewall. At the moment I'm trying to use Barry vd Heuvel's DomPDF wrapper for Laravel and tried to:
Download the zipfile from Github (master)
Updated composer.json (not sure if its needed, but did it anyway) and added "barryvdh/laravel-dompdf": "*" in the require container.
Create the folder structure: vendor/barryvdh/laravel-dompdf
Place all files from the package in there (config-folder, src-folder and the files .gitignore, composer.json and readme.md)
Add the service provider and facade in my app.php. Service provider is listed as Barryvdh\DomPDF\ServiceProvider::class and the facade is aliased like 'PDF' => Barryvdh\DomPDF\Facade::class
Ran composer dump-autoload
After refreshing the browser I'm getting Class 'Barryvdh\DomPDF\ServiceProvider' not found. I also tried to run php artisan cache:clear and php artisan dump-autoload but the last one fails over the fact it can't find Barryvdh\DomPDF\ServiceProvider.
What have I forgotten to do to make it work?
Update
I've tried the suggested answer from Wouter J and the composer.json now looks like:
..
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Barryvdh\\DomPDF\\": "vendor/barryvdh/laravel-dompdf/src"
},
..
I've verified if the composer dump-autoload had any effect but I think it had. Because the entry is now also listed in vendor/composer/autoload_psr4.php like:
return array(
// more entries
'Barryvdh\\DomPDF\\' => array($vendorDir . '/barryvdh/laravel-dompdf/src'),
'App\\' => array($baseDir . '/app'),
);
I believe at this point this is working, but the Facade isn't responding. When I try to call something like PDF::loadView(...) and I let PhpStorm import the class (vendor/barryvdh/laravel-dompdf/src/PDF.php) it throws an error I can't call the method loadView statically. According to the documentation I should be able to call it like this:
$pdf = PDF::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');
But that results in Non-static method Barryvdh\DomPDF\PDF::loadView() should not be called statically, assuming $this from incompatible context on my end.
Suggestions?
Composer autoload still doesn't know anything about how to download the package. You have to configure autoloading like this:
{
"autoload": {
"psr-4": { "Namespace\\Of\\The\\Package\\": "vendor/the/package" }
}
}
I know this question is old, but since I don't see any solution, here is mine: I had exactly the same problem. Was able to solve by running composer dumpautoload on my localhost and then copied the folder 'vendor/composer' to the shared hosting without an SSH access. Hope this will help someone in similar situation.
The problem addresses that application don't know about DomPDF\ServiceProvidor or anything related to DomPDF because barryvdh/laravel-dompdf itself depends dpmpdf/dompdf package which is still missing and does not comes with barryvdh/laravel-dompdf
the package dompdf/dompdf also depends on several extension i.e.
PHP version 5.3.0 or higher
DOM extension
GD extension
MBString extension
php-font-lib
php-svg-lib
have a look at package here https://packagist.org/packages/dompdf/dompdf download this and put in your vendor directory then update your composer dumpautoload it should be working

Where exactly does laravel require the illuminate folder?

Looking at the laravel composer.json it seems to autoload the app directory but not the laravel illuminate framework.
It is listed as a require in the composer file. So ok, you can do a composer install and it will pull in the framework to the vendor directory. But where does the laravel app require the illuminate framework now for usage? Maybe I'm lacking composer knowledge here but I can't figure it out.
Looking at the illuminate environment it seems to come with it's own composer file that autoloads its entire folder.
I'm trying to look at the laravel structure because I'm currently working on a little project of my own with a src directory and an app directory but I can't seem to autoload both folder with something like this:
{
"autoload": {
"psr-4": {
"Cinematix\\": "src",
"App\\": "app"
}
}
}
Should this be able to work? If not, how would I implement something like this? Make a php package of my src folder myself?
Composer creates vendor/autoload.php which is then required by Laravel in bootstrap/autoload.php.
The way composer works is when you update or install a package it will regenerate that file by scanning each of the packages composer.json files, so theres conveniently just 1 file you need to include in your project to load all of your dependencies.
As for your own package, what you have there should work. Have you run composer dump-autoload after updating your composer.json?

Categories