soyuka/stubs-mongodb
Laravel stub overrides to generate models/migrations geared for MongoDB usage. Adds MongoDB-friendly boilerplate when running artisan make commands so new classes start with the right base classes, traits, and conventions for jenssegers/mongodb-style projects.
Installation Add the package via Composer:
composer require soyuka/stubs-mongodb
No additional configuration is required—this package provides PHPStorm stubs for the ext-mongodb extension.
Where to Look First
ext-mongodb is installed and enabled in your PHP environment (php -m | grep mongodb).First Use Case
mongodb (e.g., via jenssegers/laravel-mongodb).Client, Collection, Manager).find(), insertOne()).Leveraging Stubs in Laravel
jenssegers/laravel-mongodb for seamless MongoDB integration:
use Jenssegers\Mongodb\Manager;
use MongoDB\Client;
$manager = app(Manager::class);
$client = new Client('mongodb://localhost:27017');
$collection = $client->selectCollection('db', 'users');
Client, Collection, BSON, and Driver classes.find(), aggregate(), updateOne().Workflow Integration
laravel-mongodb models:
php artisan ide-helper:generate
Mockery or PHPUnit + mongodb-mock):
$mockClient = Mockery::mock('overload:MongoDB\Client');
$mockClient->shouldReceive('selectCollection')->andReturnSelf();
Custom Stubs Extension
vendor/soyuka/stubs-mongodb/stubs/
stubs/ in your project root and configure PHPStorm to use them:
File > Settings > Languages & Frameworks > PHP > Stub Files.Stub Version Mismatch
ext-mongodb updates. Verify compatibility by checking:
ext-mongodb requires PHP 7.4+).php -i | grep "mongodb").IDE Caching Issues
.idea directory and regenerate it (File > Settings > IDE Settings > Build, Execution, Deployment > Invalidate Caches).Laravel-Mongodb-Specific Quirks
jenssegers/laravel-mongodb wraps MongoDB classes. Stubs won’t cover Laravel-specific methods (e.g., Model::query()).@mixin in IDE helper files:
<?php
/** @mixin \MongoDB\Driver\Manager */
class MongoDBManager {}
Verify Stubs Are Loaded
Client) in PHPStorm.selectCollection()—if stubs work, you’ll see a tooltip with parameters/return types.Fallback for Missing Stubs
@var annotations:
/** @var \MongoDB\Driver\Cursor $cursor */
$cursor = $collection->find([]);
Extending Stubs for Namespace Conflicts
App\Services\MongoDB), create a stub file like:
stubs/App/Services/MongoDB.stub
With content:
<?php
namespace App\Services {
class MongoDB extends \MongoDB\Client {}
}
Add Custom MongoDB Classes
stubs/ and reference them in phpstorm.meta.php:
return [
'stubs' => [
'App\\Services\\MongoDB\\' => 'stubs/App/Services/MongoDB/',
],
];
Integrate with Laravel Packages
spatie/laravel-mongodb or other MongoDB packages, check their docs for stub compatibility. Contribute missing stubs to this package or JetBrains’ repo.CI/CD Pipeline Check
vendor/bin/phpstan analyse --level=5 --generate-mock-files
How can I help you explore Laravel packages today?