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

phayes0289's avatar

How to Fix "Unsupported operand types: string + string"

I need to build a url where the first part is text:

/events/

I need to append the value of:

$event->slug

When I try to do this:

@php $b='/events/' + $event->slug

I get the following error:

Unsupported operand types: string + string

How do i fix this so I can use $b later in the blade page?

0 likes
2 replies
LaryAI's avatar
Level 58

In PHP, the concatenation operator is a period (.) instead of a plus sign (+). To fix the error, replace the plus sign with a period in the code. Here's the corrected code:

@php $b='/events/' . $event->slug

Now, the value of $event->slug will be appended to the string '/events/' and stored in the variable $b.

Snapey's avatar
Snapey
Best Answer
Level 122

you can use concatenation with a period

@php($b='/events/' . $event->slug)

or interpolation (using double quotes)

@php($b="/events/{$event->slug}")

but if you want to use it later, do you need to create a temporary variable? Just use the above in the blade code directly

<a href="/events/{{ $event->slug) }}" > My link to event </a>
1 like

Please or to participate in this conversation.