laravel: Запланированная команда не может отправлять электронные письма: неопределенный индекс: HTTP_POST - PullRequest
0 голосов
/ 03 марта 2019

Я создал команду и запланировал ее.Команда отлично работает при обновлении базы.Как бы то ни было, при отправке электронной почты выдается ошибка [undefined index: HTTP_POST].Я давно искал в Google, похоже, ничего не помогло решить проблему.Любая помощь будет высоко ценится.

Я использую Laravel 5.4

Ниже мой класс для отправки

<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Http\Request;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendMailable extends Mailable
{
    use Queueable, SerializesModels;
    public $number;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($number)
    {
        $this->$number = $number;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.weekly');
    }
}

Ниже моя команда

<?php
namespace App\Console\Commands;
use Illuminate\Http\Request;
use App\Jobs;
use App\User;
use Illuminate\Support\Facades\Mail;
use Illuminate\Console\Command;
use App\Mail\SendMailable;

class WeeklyEmails extends Command {

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'update:users';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send updates on latest Internships';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct() {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle() {

        
        /*
         * This part works as expected
         * 
         */
         $jobs = User::find(1);
          $jobs->name = rand(10,100);

          if($jobs->save()){
          echo "User have been updated"."\n";
          } 
        
        
          /*
           * This part does not work at all it returns the: [undefined index: HTTP_POST] error
           * 
           */
       
           Mail::to('example@gmail.com')->send(new SendMailable(5));
       
        
      
    }

}

Это мой kernel.php

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        Commands\WeeklyEmails::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('update:users')
                   ->daily();
    }

    /**
     * Register the Closure based commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        require base_path('routes/console.php');
    }
}
...