我如何在控制器上运行foreach?

问题描述 投票:0回答:1

我想发送几封电子邮件,以便将它们链接到过渡表中,很好,问题是,当我使用该命令时,它仅向我发送一封电子邮件,而每个用户都不会重复,因为应该因为在使用foreach时,我应该为每个接听的用户发送一封电子邮件,同时分别复查每个查询,如果有多个用户抓住了我,那么我不知道命令为什么只向我发送一封电子邮件。我希望您能为我提供帮助,另一方面,我也想使用sis变量的电子邮件,但是在“邮件”中使用它时,它告诉我说该变量不存在。谢谢大家。

我的控制器:

<?php

namespace App\Console\Commands;

use App\p;
use App\User;
use App\Pe;
use App\Mail\SendMailable;
use Illuminate\Console\Command;
use Carbon\Carbon;
use Illuminate\Support\Facades\Mail;

class Alertc extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'S:AC';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send works';

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

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


           $hour= 14;
        $minute= 0;
        $second=0;
        $year= date("Y");
        $month= date("m");
        $day=date("d");
        $hourM=date("H");
        $dayy= now();

        $datelim=Carbon::Create($year,$month,$day,$hour,$minute,$second);
        $datedif=Carbon::Create($year,$month,$day,$hourM,$minute,$second);
        $dateen= $Datedif->addHour();
        $intervalH= $dayy->diffInHours($datelim);
        $intervalM= $dayy->diffInMinutes($dateen);

        $systems = User::where('codarea','>',0)->get();
        foreach ($systems as $system) {
            $sis = User::select('users.email', 'users.id', 'users.name', 'p.description', 'p.Dateen')
             ->join('pa', 'pa.user', '=', 'users.id')
             ->join('p', 'p.coddate','=','pa.env')
             ->where('p.read_at', '=', 0, 'AND')
             ->where('pa.user', '=', $system->id)
             ->where('p.Dateen', '>', $dayy)

              ->get();     


        $data = ['name' => "Alert" , 'periods' => $sis, 'Periodres' => $intervalH, 'Periodresm' => $intervalM,
        'Hactual' => $dayy, 'Hlimit' => $dateend];

    Mail::send('emails.welcome', $data, function($message) {

        $message ->from('[email protected]', 'ALERT');
        $message ->to('[email protected]')->subject('Alert');

    });
    return "La alert is finished";
    }
    }
}

我的看法:

<!DOCTYPE html>
<html>
<head>
    <title>Message Sent</title>
</head>
<body>
        <ul class="list-group">

            Good morning the next works is:
            @foreach($periods as $period)
            <li class="list-group-item">
                must send 
            <b>{{$period->description}}</b>
            @if($Hactual<$Hlimit)
            the limit is

            {{$Periodres}} Hours and

            {{$Periodresm}} Minutes.

           @elseif($Hactual>$Hlimit)
           is finished. 
           @endif


   </li>
@endforeach
<b><h6>Always with you</h6></b>
        </ul>
</body>
</html>

这是我想在邮件中使用sis变量时的控制器:

namespace App\Console\Commands;

use App\p;
use App\User;
use App\Pe;
use App\Mail\SendMailable;
use Illuminate\Console\Command;
use Carbon\Carbon;
use Illuminate\Support\Facades\Mail;

class Alertc extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'S:AC';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send works';

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

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


           $hour= 14;
        $minute= 0;
        $second=0;
        $year= date("Y");
        $month= date("m");
        $day=date("d");
        $hourM=date("H");
        $dayy= now();

        $datelim=Carbon::Create($year,$month,$day,$hour,$minute,$second);
        $datedif=Carbon::Create($year,$month,$day,$hourM,$minute,$second);
        $dateen= $Datedif->addHour();
        $intervalH= $dayy->diffInHours($datelim);
        $intervalM= $dayy->diffInMinutes($dateen);

        $systems = User::where('codarea','>',0)->get();
        foreach ($systems as $system) {
            $sis = User::select('users.email', 'users.id', 'users.name', 'p.description', 'p.Dateen')
             ->join('pa', 'pa.user', '=', 'users.id')
             ->join('p', 'p.coddate','=','pa.env')
             ->where('p.read_at', '=', 0, 'AND')
             ->where('pa.user', '=', $system->id)
             ->where('p.Dateen', '>', $dayy)

              ->get();     


        $data = ['name' => "Alert" , 'periods' => $sis, 'Periodres' => $intervalH, 'Periodresm' => $intervalM,
        'Hactual' => $dayy, 'Hlimit' => $dateend];

    Mail::send('emails.welcome', $data, function($message) {

        $message ->from('[email protected]', 'ALERT');
        $message ->to(sis->email)->subject('Alert');

    });
    return "La alert is finished";
    }
    }
}
laravel foreach command
1个回答
0
投票

[您在此部分中缺少$字符:

 $message ->to(sis->email)->subject('Alert');

必须为:

   $message ->to($sis->email)->subject('Alert');
© www.soinside.com 2019 - 2024. All rights reserved.