Anna Jeanine
Anna Jeanine

Reputation: 4125

Declaring a HTML link in Laravel Controller

I have a function that replaces certain tags in an email body that the user can generate. In the function I have an array defined that contains the tags as keys and the wanted value as value:

$mailVars = array(
    '[fullname]'      => $user->fullname,
    '[first_name]'    => ($user->fullname) ? ' '.strtok($user->fullname, ' ') : '',
    '[email]'         => $user->email,
    '[username]'      => $user->email,
    '[activation_url]'=> $user->confirmation_code ? route('confirm.registration', [$user->confirmation_code, $user->email]) : "#"
);

What I would like is the [activation_url] to be an link. Because now it leave a unpleasant long looking string that needs to be copy-pasted. What I have tried:

'<a href="'.$user->confirmation_code ? route('confirm.registration', [$user->confirmation_code, $user->email]) : "#".'"> Link </a>' // just doesn't work at all... nothing of the link elements is seen in the email nor a link. 

Also tried using a HTML::linkaction but this returns an array and string was expected error is thrown.

Upvotes: 1

Views: 1313

Answers (1)

malarzm
malarzm

Reputation: 2966

You need to wrap ternary operator in ( and ) for correct precedence of operators, see this snippet for comparison: https://3v4l.org/DUM5t

Upvotes: 2

Related Questions