Trying to use a composer package in laravel - php

Im using Laravel 5.8.
Im trying to use the following package
https://packagist.org/packages/s1lentium/iptools
To install it i have run:
composer require s1lentium/iptools
Confirmed the require line is in the composer.json
"s1lentium/iptools": "^1.1"
and that the package is in "vendor/s1lentium/iptools/"
How can i reference it in the code (controller or even in a view)??
When I try to use the IP class Laravel cannot find it.
I've researched a lot and but without success. Hope anyone can lead me to the correct step.
Thanks!

Run composer dump-autoload
You must call the IP class with \IPTools\IP, or use it:
use IPTools\IP;
Hope it helps.

Related

Class 'Spatie\YamlFrontMatter\YamlFrontMatter' not found

I need help. I installed Yaml-front-matter via composer, everything was good. But if I use this class in my project, I get this very strange error. Why laravel doesn't see this class?
I do not find a solution with google.
I tried commands: php artisan optimize: clear, composer dump-autoload
but they don't help.
Thanks in advance.
screen to show the problem
Replace this
$document = YamlFrontMatter::parseFile(resource_path('posts/my-fourth-post.html');
with this
$document = \Spatie\YamlFrontMatter\YamlFrontMatter::parseFile(resource_path('posts/my-fourth-post.html');
It works.
Source: https://laracasts.com/discuss/channels/laravel/class-yamlfrontmatter-not-found-laravel-docker-composer
I was following a laracasts tutorial and ran into the same issue because I had missed they went through installing the package at the start of the video. I resolved it by just running:
composer require spatie/yaml-front-matter
The docs helped me out with resolving this, as there are a few other YAML related front-matter packages out there too.
https://github.com/spatie/yaml-front-matter.

laravel7, is there mindmap for login process?

I am creating my first package with Laravel 7.
Idea is make login and register process inside it.
Login and Register forms are working,
and process logic work aswell.
When I am calling them from route-file directly Blade form.
But
I have added login and register controller.
After login form send request to logged in,
comes issues:
Issue 1) Trait Illuminate\Foundation\Auth\AuthenticatesUsers
not found.
Tried so far:
added "laravel/ui" to Composer.json inside my package.
---- Edit ---
I found "illuminate/auth" from Github/Laravel/framework/blob/7.x/src/illuminate/Auth/composer.json
namespace is same as error.
installed but still same error.
Q) Do I miss some other package which calls User trait ?
Thanks Mika.
--- EDIT ----
I have been searcing few days to way to do it.
Found https://laracasts.com/discuss/channels/laravel/create-laravel-route-inside-another-composer-packages
But it is for Larave 5.X, is it still valid way to fix this problem ?
If you want to use Laravel's built in authentication, this is how you set it up:
Run
composer require laravel/ui
Then run
php artisan ui:auth
and
php artisan migrate
If you want to use Vue with the UI scaffolding you can run php artisan ui vue --auth instead of php artisan ui:auth.
So I'd recommend to undo what you did (seems like you didn't run through the install steps properly) and then follow the steps above. More info in the official documentation.
The trait you're trying to use is in fact inside laravel/ui, so you should still require this package in your composer.json: https://github.com/laravel/ui/blob/2.x/auth-backend/AuthenticatesUsers.php
I would also try running composer dump-autoload after installing the laravel/ui package (this should clear any cached autoloaders).
Also, please don't forget to properly import the AuthenticatesUsers trait in your controller:
use Illuminate\Foundation\Auth\AuthenticatesUsers;
...
class LoginController extends Controller
{
use AuthenticatesUsers;
...
}

Getting Class Rap2hpoutre LaravelLogViewerServiceProvider not found error in a school management software

I'm trying to use Unifiedtransform a school management software in Github. I got this error Class 'Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider' not found while trying to run composer install --no-dev.
How to fix this error?
you try add in app dir. in providers dir in a,
class LaravelLogViewerServiceProvider extends ServiceProvider like this.done
https://github.com/rap2hpoutre/laravel-log-viewer/blob/master/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php
I had the same error message while running a migration on a laravel project I cloned from GitHub.
error message
I discovered that this file is part of the package rap2hpoutre/laravel-log-viewer.
Please go to their download page to download this composer package.
You can also run the command below:
composer require rap2hpoutre/laravel-log-viewer
to solve the problem
Class "Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider" not found

How to autoload another package with own composer

EDIT with important note: The package I want to include does not use composer autoload. I'd have to use their hacky one and I want to avoid that.
I know how composer mostly works and I have package that can be a dependency (that's important, I know how to make this work in one project, but that's not what I'm asking).
What I need?
Somebody requires my package
composer require tomas/my-package
It will install
It will autoload my package with PSR-4
It will autoload 3rd party package as well
I have already tried something like this:
"autoload": {
"psr-4": {
"MyPackage\\": "src",
"PHP_CodeSniffer\\": "../../squizlabs/php_codesniffer/src"
}
}
I've tried that in one of my dependencies and it doesn't work :(.
Also, I've already talked to the package author and he doesn't want to use composer autoloading. He prefers his own.
Thanks for any help!
None if these answer are related to problem I desribed, so I try to post best solution so far:
I got inspired in PHPStan, which has feture to autoload directories, that were missed in composer (practically same issue).
I've added RobotLoader:
composer require nette/robot-loader
Then create LegacyCompatibility class with static method:
use Nette\Loaders\RobotLoader;
// ...
public static function autoloadCodeSniffer(): void
{
$robotLoader = new RobotLoader;
$robotLoader->acceptFiles = '*.php';
$robotLoader->setTempDirectory(sys_get_temp_dir() . '/_robot_loader');
$robotLoader->addDirectory(getcwd() . '/vendor/squizlabs/php_codesniffer/src');
$robotLoader->register();
}
And I call it, when needed:
LegacyCompatibility::autoloadCodeSniffer()
Works like a charm. But still opened to better solutions +1 !
Github Permalink
You are doing one big NO-NO in your composer.json file: You are defining autoloading for code that is not in your package.
This will fail, as you found out already.
And I wonder why you are struggling with integrating the PHP Codesniffer, because that package has a working autoloading definition included. All you'd need to do is "require": { "squizlabs/php_codesniffer": "^3.0#RC" } (if you really need the latest 3.x release candidate, otherwise ^2.8.0 would be a better idea).
If you require PHP_Codesniffer instead of somehow referencing it in your autoloading, then Composer will do everything to integrate that package: download it, add it to the autoloader, and run it's code if necessary. And anyone depending on YOUR package will also get this dependency installed.
The only problem you state is that "it doesn't work", which is no sufficient description of a problem because you lack describing what you did in your code, and what error message you got. Also state what you expected to happen, and what happened instead (and how this deviated from your expectation if this isn't obvious).

using PayWithAmazon with symfony 2 - installed with Composer

I installed this package via composer:
composer require amzn/login-and-pay-with-amazon-sdk-php
composer update
I added this to my Controller file:
use PayWithAmazon\Client;
... and would like to use the Client class, provided with this package.
$amazonClient = new PayWithAmazon\Client($this->amazonCredentials);
The error message of the framework:
ClassNotFoundException in CartController.php line 185: Attempted to load
class "Client" from namespace "**Microsite\FrontBundle\Controller\PayWithAmazon**".
Did you forget a "use" statement for e.g.
"Symfony\Bundle\FrameworkBundle\Client",
"Symfony\Component\BrowserKit\Client",
"Symfony\Component\HttpKernel\Client",
"Guzzle\Service\Client" or "Guzzle\Http\Client"?
`
Can anyone tells me what i do wrong?
How do I change the namespace for "Client" class from Microsite\FrontBundle\Controller\PayWithAmazon to the right one?
(I did not have problems with other packages...)
Cheers
Greg
I will suggest you do follow
use PayWithAmazon\Client as AmazonClient;
...
$amazonClient = new AmazonClient($this->amazonCredentials);

Categories