有没有办法在Laravel模板中嵌套{{}}表达式?

I have a resource route generated by Artisan command as

Route::resource('posts','PostsController');

the URI of this route is posts/{post}/edit which require a dynamic value in the middle. But because I'm using the url() method to link all of my routs I am forced to nest the template expression as:

<a href="{{url('/posts/{{$show->id}}/edit')}}" class="btn btn-sm">Edit</a>

This is giving me an error: NotFoundHttpException because it couldn't get the {{$show->id}} part. How can I fix this?

In PostsController, create a new variable that you want to show up in the template. You should be able to use the url() function within a controller. (See here) Pass this value to the template like you normally would.

Just in case: documentation on how to pass values to a template

Use <a href="<?php echo url('/posts/'.$show->id.'/edit')?>" class="btn btn-sm">Edit</a> with out the use of {{}} notation.

You need double quote and remove one bracket

Do you looking for something like this?

@foreach($posts as $post)
<a href="{{url("/posts/{$post->id}/edit")}}" class="btn btn-sm">Edit</a>
@endforeach