我已经在kernel.php
中创建了命令,该命令运行了twoDaily()。我也想用按钮附加它,这样我可以通过单击该按钮来运行此命令。当我单击按钮时,它应该会在此时运行。
[目前,我刚刚创建了两次每日命令,我需要更好的方法来实现按钮提示。
kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->job(new \App\Jobs\ResendAttachment)->twiceDaily(1, 13);
}
我想通过服务器上的cron作业和按钮来运行命令
添加路线示例:
Route::get('/resentattachment', 'YourController@resentattachment')->name('resent.attachment');
从您的控制器调用命令
class YourController extends Controller
{
public function resentattachment()
{
Artisan::call('yourcommand');
echo 'Sent successfully';
//add other stuff like a success view
}
}
您现在正在做的工作是安排每天运行两次。但是,您也可以manually dispatch a job在该实例上运行(或在跑步者有空处理您的工作时立即运行)。
您可以创建一个控制器动作,以便单击该按钮时,控制器将分派作业。例如,
<?php
namespace App\Http\Controllers;
use App\Jobs\ResendAttachment;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ExampleController extends Controller
{
/**
* Resend attachment.
*
* @param Request $request
* @return Response
*/
public function resendAttachment(Request $request)
{
ResendAttachment::dispatch();
}
}