@asset Blade directive returning unhashed assets in prod

I’m running into an issue where I’m using the @asset blade directive to import an image asset into a template. Like so:

@php
  $logos = [
      'aaa' => 'aaa.png',
      'bbb'           => 'bbb.jpg',
      'ccc'          => 'ccc.jpg',
      'ddd'           => 'ddd.jpg'
  ];
@endphp
@foreach($logos as $key => $logo)
  <img class="{{$key}}" src="@asset(images)/{{$logo}}" />
@endforeach

But in production, these are the assets that are returned in the template:
/dist/images/aaa.png
/dist/images/bbb.jpg
/dist/images/ccc.jpg
/dist/images/ddd.jpg

When they should be (according to the assets.json file):

"images/aaa.png": "images/aaa_54ffc7f2.png",
"images/bbb.jpg": "images/bbb_b938bb7b.jpg",
"images/ccc.jpg": "images/ccc_50292fa7.jpg",
"images/ddd.jpg": "images/ddd_7b2b82a4.jpg",

ETA: This is on my local environment still. I’m trying to simulate production. Is there an environment variable I need to change anywhere? I’m not using Bedrock or Trellis, but instead Local by Flywheel.

You’re looking for an asset named “images” and it’s not finding that, so it just fails and returns “{dist_url}/images” to which you’re appending “/{{$logo}}.”

Try:

<img class="{{$key}}" src="@asset(images/{{$logo}})" />
1 Like

AH! Thank you! I am glad it was something stupid like that.