我希望你能帮我翻译一下如何将数据传递到我在Artisan命令中创建的handle方法中。
目前我的代码如下: (如果我在handle方法中使用DD打印出来的数据,它可以工作,所以它与Artisan命令链接)
控制器:
public function update(Request $request, $slug) {
// Get the user assocated with Listing, and also get the slug of listing.
$listing = $request->user()->listings()->where('slug', $slug)->first();
// Flash success message after every update
Message::set('Alright!', 'Your changes were saved successfully.');
Artisan::call('emails:sendIfGuideUpdated');
// More code here...
}
我创建了一个工匠命令来处理发送电子邮件的功能:
class SendEmails extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'emails:sendIfGuideUpdated';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send out an email every minute to users that have favored a guide when that Guide updates their Listing';
public $listing;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(Listing $listing)
{
$this->listing = $listing;
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// Get the data from the Guide Listing that was updated
$name = $this->listing->name;
dd($name);
// Send an email to the Admin notifying that a comment was made under a blog post.
}
}
这是我的内核文件,将处理邮件发送时的情况:
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\Inspire::class,
Commands\SendEmails::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('emails:sendIfGuideUpdated')->everyMinute();
}
}
我在将列表信息传递到处理方法中遇到了问题。正确的做法是什么?