1
我會將數據傳遞到我在我的Artisan Command中創建的處理方法中嗎?如何將數據傳遞到Artisan處理命令 - Laravel 5.2
這是我到目前爲止有: (如果我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();
}
}
林具有麻煩傳入清單信息插入處理方法。這樣做的正確方法是什麼?
是幫助你的?如果不是你在哪裏發現問題? – Maraboc