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

Tommy001's avatar

How can I expand a variable inside double curly braces

I have an uploadcontroller for images. When the image is stored with the storage method and also stored in the appropriate db table I redirect back to the view I came from, like this (with the filename stored in the session):

'return redirect()->back()->with('bildnamn', $fileNameToStore);'

Then, in the view, I want to show the uploaded image, so I fetch it back from the session:

'@if (session()->has('bildnamn'))

@php $bildnamn = session('bildnamn');

echo $bildnamn; {{-- the image name shows here --}}

@endphp

<img src="{{ asset('storage/uploads/@php $bildnamn @endphp') }}"> {{-- but how can I expand the variable here? --}}

@endif '

0 likes
3 replies
Cronix's avatar
Cronix
Best Answer
Level 67
@if (\Session::has('bildnamn'))
<img src="{{ asset('storage/uploads/' . \Session::get('bildnamn')) }}">
@endif
Tommy001's avatar

Thanks Cronix and Nash! That worked!

1 like

Please or to participate in this conversation.