我与Laravel Forge一起在Digital Ocean中托管了我的应用程序,并创建了一个工匠命令来按计划运行[夜间]。
artisan命令可通过终端顺利运行,但在从Laravel Forge手动通过Scheduled Jobs
运行时,不会返回没有此类文件或目录。
该作业的命令是:
php /home/forge/sitename.com/artisan Instagram:fetch
Artisan命令php /home/forge/sitename.com/artisan Inspire
即php artisan Inspire 返回正确的输出。
上述定制工匠返回没有此类文件或目录
app \ Console \ Commands \ FetchInstagram.php 的处理方法:
public function handle()
{
$instagram = new Instagram('api-key');
$posts = $instagram->media(); //gets 20 latest insta posts of a user
// dd($posts);
$fromDBs = Insta::orderBy('id', 'desc')->take(20)->get(); //get last 20 rows from table
foreach( $posts as $post)
{
Insta::firstOrCreate([
'thumb_link' => $post->images->thumbnail->url ,
'standard_link' => $post->images->standard_resolution->url ,
'caption' => $post->caption->text
]);
}
}
来自Kernel.php
的代码:
protected $commands = [
'App\Console\Commands\FetchInstagram'
];
protected function schedule(Schedule $schedule)
{
$schedule->command('Instagram:fetch')
->daily();
}