In my view, I want to print a controller uri like this ShopController@show
.
set the var $controller = 'ShopControll';
in the view:
action($controller.'@show',$id)
but there are some error occured:
ErrorException in UrlGenerator.php line 603:
Action App\Http\Controllers\ShopController<?php echo $__env->yieldSection(); ?> not defined.
if like this:
action('ShopController@show',$id)
it works, output is:
http://example.com/show/1
So, what's the difference?
@show is a blade directive, blade parse it you want to show this as section please check here example
@section('sidebar')
This is the master sidebar.
@show
https://laravel.com/docs/5.2/blade#template-inheritance
you can modify you method like this
action($controller,'show',$id)
For Laravel >= 5.3 you can use a combination with @php @endphp
:
@php
echo @action($controller.'@show', ['id' => $id])
@endphp
For earlier versions, I think (tested only on 5.3 again), this should work too:
{{ @action($controller.'@show', ['id' => $id])}}