https://github.com/markwalet/laravel-packagist
A Laravel wrapper for the spatie/packagist-api package.
https://github.com/markwalet/laravel-packagist
laravel package packagist
Last synced: 10 months ago
JSON representation
A Laravel wrapper for the spatie/packagist-api package.
- Host: GitHub
- URL: https://github.com/markwalet/laravel-packagist
- Owner: markwalet
- License: mit
- Created: 2020-04-08T10:16:14.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-02-03T09:20:45.000Z (over 1 year ago)
- Last Synced: 2025-07-31T14:59:33.159Z (10 months ago)
- Topics: laravel, package, packagist
- Language: PHP
- Size: 35.2 KB
- Stars: 13
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Packagist
[](LICENSE.md)
[](https://packagist.org/packages/markwalet/laravel-packagist)
[](https://github.com/markwalet/laravel-git-state/actions)
[](https://codecov.io/gh/markwalet/laravel-packagist)
[](https://github.styleci.io/repos/254053836)
[](https://packagist.org/packages/markwalet/laravel-packagist)
A Laravel wrapper for the [spatie/packagist-api](https://github.com/spatie/packagist-api) package.
## Installation
You can install this package with composer:
```shell
composer require markwalet/laravel-packagist
```
Laravel uses Package auto-discovery, so you don't have to register the service provider. If you want to register the service provider manually, add the following line to your `config/app.php` file:
```php
MarkWalet\Packagist\PackagistServiceProvider::class,
```
## Usage
There are two main ways how you can make Packagist calls:
**Using the application container**
```php
/** @var \Spatie\Packagist\PackagistClient $client */
$client = app(\Spatie\Packagist\PackagistClient::class);
$client->getPackage('markwalet', 'laravel-packagist');
```
**Using the facade**
```php
Packagist::getPackage('markwalet', 'laravel-packagist');
```
### Available methods
**List package names**
```php
// All packages
Packagist::getPackagesNames();
// Filter on type.
Packagist::getPackagesNamesByType('composer-plugin');
// Filter on organization
Packagist::getPackagesNamesByVendor('markwalet');
```
**Searching for packages**
```php
// Search packages by name.
Packagist::searchPackagesByName('packagist');
// Search packages by tag.
Packagist::searchPackagesByTags('psr-3');
// Search packages by type.
Packagist::searchPackagesByType('composer-plugin');
// Combined search.
Packagist::searchPackages('packagist', ['type' => 'library']);
```
**Pagination**
Searching for packages returns a paginated result. You can change the pagination settings by adding more parameters.
```php
// Get the third page, 10 items per page.
Packagist::searchPackagesByName('packagist', 3, 10);
```
**Getting package data.**
```php
// Using the Composer metadata. (faster, but less data)
Packagist::getPackageMetadata('markwalet/laravel-packagist');
Packagist::getPackageMetadata('markwalet', 'laravel-packagist');
// Using the API. (slower, cached for 12 hours by Packagist.
Packagist::getPackage('markwalet/laravel-packagist');
Packagist::getPackage('markwalet', 'laravel-packagist');
```
**Get Statistics**
```php
$packagist->getStatistics();
```
## Configuration
By default, the api url for Packagist is set to `https://packagist.org`. If you want to override that, you can add the following code block to your `config/services.php` file:
```php
'packagist' => [
'base_url' => 'https://packagist.org',
'repo_url' => 'https://repo.packagist.org',
],
```