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

wonder95's avatar

Error passing signed URL to <x-mail::button> in Blade template

I have a mailable created for sending out a bulk email, and part of the email is a button that contains a signed link used to confirm attendance at a class. I'm using the public properties in the mailable class to pass in the variable values to the template:

    public String $confirm_url;

    public function __construct(Carbon $class_date, Carbon $next_class_date, User $user)
    {
        $this->next_class_date = $next_class_date->format('l, F jS');
        $this->day_number= $class_date->format('jS');
        $this->day_name= $class_date->englishDayOfWeek;
        $this->month= $class_date->month;
        $this->full_date = $class_date->format('l, F jS, Y');
        $this->picture_date = $class_date->subDays(2)->format('F jS');
        $this->confirm_url = URL::temporarySignedRoute('application.class.confirm', now()->addWeeks(2), ['user' => $user->id]);
    }

This works great for every variable except $confirm_url. When I pass in the URL like this:

<x-mail::button :url="{{ $confirm_url }}">
Confirm Attendance
</x-mail::button>

where the url is

http://mysite/application/confirm/2020?expires=1701231332&signature=71508ff58a2ef3b5d3d977a1bc87e0f0a5d65befec1f59d4f7446910a59db6c9

I get this error

  syntax error, unexpected token "<" (View: /Users/steve/Sites/laravel/members/resources/views/mail/orientation-class.blade.php)

  at storage/framework/views/ee13e55a8faf55a2c045cd56bfb754962165155b.php:45

where the line in error in the compiled view is

<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => $__env->getContainer()->make(Illuminate\View\Factory::class)->make('mail::button'),'data' => ['url' => <?php echo e($confirm_url); ?>]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>

where the <?php and $confirm_url are highlighted as being in error and the IDE message says the variable doesn't exist.

Am I passing the value in incorrectly?

0 likes
2 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

It looks like the issue is with the Blade syntax when passing the $confirm_url variable to the <x-mail::button> component. You should not use the curly braces {{ }} inside the Blade component attribute since it's already in a PHP context. Instead, you should pass the variable directly without the curly braces.

Here's how you can pass the $confirm_url to the <x-mail::button> component correctly:

<x-mail::button :url="$confirm_url">
Confirm Attendance
</x-mail::button>

By removing the curly braces, you're directly passing the PHP variable to the component, which should resolve the syntax error you're encountering.

Make sure that the $confirm_url variable is accessible in the Blade view where you're using the <x-mail::button> component. If the variable is defined in a Mailable class, it should be automatically available in the Blade view as long as you're passing the Mailable to the view correctly.

1 like
Snapey's avatar

to correct Lary

By removing the curly braces, you're directly passing the PHP variable to the component, which should resolve the syntax error you're encountering.

No, by removing the curly braces you are directly passing the name of the php variable you want the component to evaluate

Please or to participate in this conversation.