I am trying to develop a Laravel package with a helper function, which returns a view. I have uploaded on GitHub already https://github.com/faisalahsan/laravel-breadcrums. When I install it through Packagist https://packagist.org/packages/faisalahsanse/laravel-breadcrums, it installs successfully, but when I register it in the provider array in my app.php as Faisalahsanse\Breadcrums\BreadcumsServiceProvider::class,. It gives the following error:
Class 'Faisalahsanse\Breadcrums\BreadcumsServiceProvider' not found
I don't know where I am getting wrong.
Any suggestions?
Your namespace is wrong https://github.com/faisalahsan/laravel-breadcrums/blob/master/src/BreadcumsServiceProvider.php#L2
It should be Faisalahsan\LaravelBreadcrums. As this namespace you are adding in the composer.json file in psr-4 autoload.
Also your provider to add will be Faisalahsan\Breadcrums\BreadcumsServiceProvider::class
Related
I have tried to install telescope according to Jeffrey's video.
I am using the latest version of laravel. I have installed according to the laravel documentation for installing as dev.
But, don't get the file config/telescope.php and app\Providers\TelescopeServiceProviders.php in config folder.
Need to mention:
--I have used use Laravel\Telescope\TelescopeServiceProvider namespace in AppServiceProvider.php
I have an laravel application and I need to install this package lunar-calendar
I install it and the package shows in vendor folder:
The package documentation tells to required the package like this:
use yzha5\LunarCalendar;
I put this way but also try this in controller:
use App\yzha5\LunarCalendar;
but returns not found.
I also run the command to publish vendor but doesn't work.
How can I use this package?
The package doesn't contain a service provider, so publish vendor will accomplish nothing really.
use yzha5\LunarCalendar;
\\ will not work because it isn't registered in your service provider that this alias equals the package path
use App\yzha5\LunarCalendar;
\\ will not work because there isn't a folder in app directory named yzha5.
Since it's just two classes and not exactly a decently build package, I'd just fetch those two files into a directory at your choosing, change the namespace and call them.
I try to create my own composer library. I've chose to use psr4 for autoloading mechanism. It works fine with the library project but something goes wrong when I add this library to another project as dependency. I expect the library project create an instance of a class which is located in main project. However this class cannot be found by composer autoloader.
My library project source is here : https://github.com/brnogz/kwinsey
My example project which uses this library like that(HelloWorld class is located in controller/HelloWorld.php file) : https://gist.github.com/brnogz/e27a1dd40ba00b818b23fe7ab8815fad
Please move all your sources to a src subfolder and use "src/" as the PSR-4 target folder. Autoloading from a project root folder is pretty much undefined behaviour.
I'm using cakephp and phpwhois
I'm copying phpwhois folder in app/vendor
in my controller :
App::import('Vendor', 'phpWhois\Whois', array('file' => 'phpWhois/Whois.php'));
whois class is extended with whpisclient class
and show me this error :
Error: Class 'phpWhois\WhoisClient' not found
File: C:\xampp\htdocs\padweb\app\Vendor\phpWhois\Whois.php
If I use composer autoloader, it shows me the same error.
see this nice article http://ceeram.github.io/blog/2013/02/22/using-composer-with-cakephp-2-dot-x/
about using composer in cakephp 2.0
it will allow you to use a global autoload.php file for all your new packages that you install with composer
let me know if it helps
I'm using Laravel 4 and I want to use a third party package within this framework. I did this to install it:
1) Add package name to composer.json file
2) Run composer update command
Now I have package available in /vendors folder. My question is, how to use it inside the Laravel now?
Looking in the config/app.php file, I can not add it to "providers" array as far as I can see, nor "aliases".
When I try to instantiate that package class directly in controller I get the error "Class not found" ( I tried full name to the class: $pack = new /vendor/package.../class.php )
Any help on how to include and use the class in the laravel greatly appreciated
If the package provides a ServiceProvider, add it to app/config/app.php.
Otherwise composer has already took care of autoloading for you, so you just have to:
$package = new Package;
In the cases where the package is namespaced, you'll have to:
$package = new PackageNamespace\Package;
To be sure, take a look at the vendor/composer/autoload_* files, usually vendor/composer/autoload_classmap.php, search for the package name or class name and you'll see how it is named. Or just take a look at the main package souce file, usually in:
vendor/vendorName/packageName/[src or lib or whatever]/Package.php
EDIT
I just installed it here and did:
Route::get('test', function()
{
dd(new WideImage\WideImage);
});
Works like a charm. This package is in the 'namespaced' case I wrote above.