Reputation: 29
I using eloquent model in lumen scheduler but show error Call to a member function connection() on null but using DB work fine.
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
use Models\Setting;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$setting = Setting::find(1);
}
}
Upvotes: 0
Views: 564
Reputation: 11
I met the same problem, in spite of uncommented the $app->withEloquent();
in bootstrap/app.php but still no working.
the workaround:
protected function schedule(Schedule $schedule) {
// no idea why the dbserviceprovider not booted
Model::setConnectionResolver($this->app['db']);
// ...
}
Upvotes: 1