Skip to content

Instantly share code, notes, and snippets.

@TerrePorter
Last active July 15, 2024 23:55
Show Gist options
  • Select an option

  • Save TerrePorter/4d2ed616c6ebeb371775347f7378c035 to your computer and use it in GitHub Desktop.

Select an option

Save TerrePorter/4d2ed616c6ebeb371775347f7378c035 to your computer and use it in GitHub Desktop.
Laravel: Giving a service provider load priority
<?php
/*
In the bootstrap/app.php file, add one of the following above the return statement.
*/
/*
Option 1, if you want to be ballsey and load before any service provider in the config/app.php file.
*/
$app->resolving(Illuminate\Foundation\Bootstrap\RegisterProviders::class, function () use ($app) {
// need? necessary? - hell no, its just because I want to
dump('I want to be first before any service provider listed in config/app.php');
$app->register(\MyClass::class);
});
/*
Option 2, load you service provider after the View service provider, aka before the vendor autoload service providers.
*/
$app->resolving('view', function () use ($app) {
dump('I want to be next in line after the view service provider');
$app->register(\MyClass::class);
});
@TerrePorter
Copy link
Author

@aariow

This might work

$app->resolving(NAMESPACE/TO/THIRD-PARTY/Service provider::class , function () use ($app) {
    $app->register(\MyServiceProvider::class);
});

Here is what i understand your looking for. You want to load your service provider after a thirparty's service provider. I am assuming this is using the auto-registere thingy. where you didn't have to put in the namespace/path to the service provider.

I haven't looks at this code in sometime, and i couldn't find the parent project where i was using it. This is my best guess as to what your wanting to do. if its not or this doesn't work, give me a better break down of the goal, laravel version, and i will make some time to dig in to it some more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment