Is it possible to inject an interface into Laravels Kernel.php? Is it possible to inject an interface into Laravels Kernel.php? laravel laravel

Is it possible to inject an interface into Laravels Kernel.php?


You are doing it wrong. I suppose you wrote your scheduled tasks directly in the Kernel in closures. Instead, wrap your commands logic in Console commands

<?phpnamespace App\Console\Commands;use App\Repositories\UserRepository;use Illuminate\Console\Command;class MyCoolCommand extends Command{    /**     * The name and signature of the console command.     *     * @var string     */    protected $signature = 'mycool:command';    protected $repository = null;    public function __construct(UserRepository $repository)    {        parent::__construct();        $this->repository = $repository;    }    /**     * Execute the console command.     *     * @return mixed     */    public function handle()    {        // your logic here    }}

and then call them in the kernel like this:

$schedule->command('mycool:command')->daily();

You can then define each command dependencies separately in the command constructor, clean up your kernel and write some testable and pretty code :)