Level 67
@if (\Session::has('bildnamn'))
<img src="{{ asset('storage/uploads/' . \Session::get('bildnamn')) }}">
@endif
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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 '
@if (\Session::has('bildnamn'))
<img src="{{ asset('storage/uploads/' . \Session::get('bildnamn')) }}">
@endif
Please or to participate in this conversation.