Laravel Packages

Detect Packages & Approaches in use within a project with Laravel Roster

Published
Detect Packages & Approaches in use within a project with Laravel Roster image

Laravel Roster is a small package created by the Laravel core team to detect which Laravel ecosystem packages are in use within a project, and it gives you an easy-to-use API to work with that data.

To use this package, install it with Composer:

composer require laravel/roster

Once installed, using it is as simple as:

use Laravel\Roster\Roster;
 
$roster = Roster::scan($directory); // Scan a directory containing a composer.lock file
$roster->packages();

Roster will scan for any packages and their versions and add them to a Collection:

An example of the dd() output of the packages returned by Laravel Roster
If you need to be more specific as to which types of packages you'd like to scan for, there are a few other helpful methods:
// Get only packages that will be used in production
$roster->packages()->production();
 
// Packages that are only used for dev
$roster->packages()->dev();

And to check for specific Laravel packages and versions in use:

use Laravel\Roster\Enums\Packages;
 
$roster->uses(Packages::MCP);
$roster->uses(Packages::VUE); // it can check for certain NPM packages as well
 
$roster->usesVersion(Packages::MCP, '0.2.0', '>=');

While the Laravel team uses Roster primarily for their own internal development, if you’re a package developer, you may find it helpful as well. In fact, if you are using Laravel Boost, then Roster is already installed as a dependency.

View the source code for Roster on GitHub.

Yannick Lyn Fatt photo

Staff Writer at Laravel News and Full stack web developer.

Sponsored

tinkerwell logo
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article