Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Daniel-Pablo's avatar

Kernel, pass data to email view

Hello i'm having a lot of problems, this is what i have at the moment, can anyone guide me?

  • in my kernel file i got this:
protected function schedule(Schedule $schedule)
    {
        //$schedule->command('inspire')->everyMinute();

        $schedule->call(function () {
            //send email every month to users
            $plans_user = servHosting::whereMonth('plan', '=', Carbon::now()->addMonth()->month)->get();

            foreach ($plans_user as $recipient) {
                $emails = $recipient->domain;
                Mail::to($emails)->send(new OrderShipped ($plans_user));
            }
            
        })->everyMinute();  
    }
  • in my orderShipped file i got this:
namespace App\Mail;

use App\Models\servHosting;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class OrderShipped extends Mailable
{
    use Queueable, SerializesModels;

    public $plans_user;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(servHosting $plans_user)
    {
        $this->plans_user = $plans_user;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('emails.orders.shipped')
        ->with([
            'domain' => $this->plans_user->domain
        ])
        ->subject('Plan de hosting proximo a vencer');
    }
}
  • in my shipped email message file i got this:
@component('mail::message')
# Plan de Hosting

Contenido del email desde el servidor {{ $plans_user->domain }}

@component('mail::button', ['url' => 'https://getweb.com.co'])
Visita nuestro sitio web
@endcomponent

Gracias equipo,<br>
{{ config('app.name') }}
@endcomponent 

What im doing wrong?

0 likes
4 replies
MichalOravec's avatar
public $plans_user;

/**
 * Create a new message instance.
 *
 * @return void
 */
public function __construct(servHosting $plans_user)
{
    $this->plans_user = $plans_user;
}

Then this will be visible in markdown

{{ $plans_user->domain }}
Daniel-Pablo's avatar

thank Michal for your answer but it doesn't work, any other idea?

MichalOravec's avatar
Level 75

Also here, you have to pass $recipient to the OrderShipped

foreach ($plans_user as $recipient) {
    $emails = $recipient->domain;
    
    Mail::to($emails)->send(new OrderShipped($recipient));
}
Daniel-Pablo's avatar

Thank you so much for all your help Michal!! i was struggling a lot of time with this

Please or to participate in this conversation.