Laravel-未在live server上自动更新Cron作业
我的Digital Ocean Ubuntu live服务器上有一个cron作业:Laravel-未在live server上自动更新Cron作业,laravel,Laravel,我的Digital Ocean Ubuntu live服务器上有一个cron作业: namespace App\Console\Commands; App/Console/Command class UpdateCreateEmployeeDepartment extends Command { protected $signature = 'updatecreateemployeedepartments'; protected $description = 'Update
namespace App\Console\Commands;
App/Console/Command
class UpdateCreateEmployeeDepartment extends Command
{
protected $signature = 'updatecreateemployeedepartments';
protected $description = 'Update or Create Employee Department';
public function __construct()
{
parent::__construct();
}
public function handle()
{
// Select all employees that haven't been updated
$employees = HrEmployee::where('is_nav_updated', 0)->where('company_id', 1)->get();
// For each of the employees selected above
foreach ($employees as $employee) {
$department = HrDepartment::where('dept_code', $employee->nav_dept_id)->where('company_id', 1)->first();
// If a department was found, update the employee
if ($department) {
$employee->department_id = $department->id;
$employee->is_nav_updated = 1;
$employee->save();
}
}
}
}
cron作业未按计划在实时服务器上自动运行。请参阅下面的控制台
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
'App\Console\Commands\UpdateCreateEmployeeDepartment',
];
protected function schedule(Schedule $schedule)
{
$schedule->command('updatecreateemployeedepartments')
->dailyAt('01:00');
}
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
我观察到,在我手动运行之前,它不会按计划自动运行:
php artisan updatecreateemployeedepartments
我如何解决这个问题
谢谢您希望在服务器中运行下面的命令以自动运行
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
更多信息检查检查我的答案,这将解决您的问题。谢谢