1

I have a running Laravel application which has the default Console/Kernel.php where all my scheduled commands are defined as usual.

But now I have another Laravel application that I am trying to merge with this existing application, and I have created a folder inside the existing Laravel application and I am using a Service Provider to load all the things. This way I can keep the code of the two projects separate but at the same time all features under the same repository.

<?php

namespace SecondApp;

use Illuminate\Support\ServiceProvider;

class SecondAppServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        include __DIR__ . '/routes/web.php';
        include __DIR__ . '/routes/api.php';

        $this->app->register('SecondApp\App\Providers\AppServiceProvider');
        $this->app->register('SecondApp\App\Providers\AuthServiceProvider');
        $this->app->register('SecondApp\App\Providers\BroadcastServiceProvider');
        $this->app->register('SecondApp\App\Providers\EventServiceProvider');
        $this->app->register('SecondApp\App\Providers\JobServiceProvider');
        $this->app->register('SecondApp\App\Providers\MailerServiceProvider');
        $this->app->register('SecondApp\App\Providers\RouteServiceProvider');
        $this->app->register('SecondApp\App\Providers\StorageServiceProvider');
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        $this->loadMigrationsFrom(__DIR__ . '/database/migrations/');

        $this->publishes([
            __DIR__ . '/config/' => config_path()
        ], 'second-app-config');

        $this->publishes([
            __DIR__ . '/resources/' => base_path('resources')
        ], 'second-app-resources');
    }
}

This is what my service somewhat looks like. Everything else seems to work well, roues, migrations, registering service providers and so on, but this second project now also has Console/Kernel.php file. And those commands are not being called yet, obviously because laravel doesn't know about it. So I am wondering how can I tell Laravel to look at that as well? Is this possible, or will I have merge the code into one main Kernel.php?

I have the same question about Http/Kernel.php as well, but I am sure if someone can suggest how to make one work, I can make the other work as well.

1 Answer 1

2
+50

To load commands, need to add them like this in the register method of service provider

$this->commands([
    App\Console\Commands\CommandOne::class,
    App\Console\Commands\CommandTwo::class,
]);

and so on, keep adding commands to the array.

And to schedule these commands refer to this answer -> How to schedule Artisan commands in a package?

So add something like this to the boot method of your service provider:

$this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
    $schedule->command('some:command')->everyMinute();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.