laravel路由问题语法错误,意外的“ opis”(T_STRING),预期为“)”

时间:2019-11-19 13:19:46

标签: php laravel

需要通过路由生成附加链接。 直到现在我写道:

<a class="btn btn-outline-light" href="{{ route('farmyw', app()->getLocale()) }}">{{ __('flipmenu.button') }}</a>

一切正常,直到我需要从翻译中给出路由名称为止。 我正在使用代码:

<a class="btn btn-outline-light" href="{{ route('{{$flip->getTranslatedAttribute('button')}}', app()->getLocale()) }}">{{ __('flipmenu.button') }}</a>

所有人都给出以下错误,对于每一个提示我将不胜感激

<?php $__currentLoopData = $flips; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $flip): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <div class="flip" farmy pv>
        <div class="front" style="background-image: url(<?php echo e(Voyager::image( $flip->image )); ?>)">
            <h1 class="text-shadow front-shadow"><?php echo $flip->getTranslatedAttribute('name'); ?></hi>
        </div>
        <div class="back" style="background-color:#304c84;">
            <h2><?php echo $flip->getTranslatedAttribute('nameback'); ?></h2>
            <p style="text-align: justify; color: white;"><?php echo $flip->getTranslatedAttribute('opis'); ?></p>
            <a class="btn btn-outline-light" href="<?php echo e(route('{{$flip->getTranslatedAttribute('opis')); ?>', app()->getLocale()) }}"><?php echo e(__('flipmenu.button')); ?></a>
            "><?php echo $flip->getTranslatedAttribute('name'); ?></a>
        </div>
    </div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


<?php echo e($flip->button); ?>

非常感谢您的帮助

我的网络路由文件如下

Route::get('/', function () {
    return redirect(app()->getLocale());
});

Route::group([
    'prefix' => '{locale}', 
    'where' => ['locale' => '[a-zA-Z]{2}'],
    'middleware' => 'setlocale'
  ], function() {

Route::get('/', 'FlipController@index')->name('menu');
Route::get('/', 'FooterController@index')->name('footer');


Route::get('/', 'MainController@index')->name('index');
Route::get('/farmy', 'PfarmController@index')->name('farmy');
Route::get('/farmyw', 'FarmywController@index')->name('farmyw');
Route::get('/kariera', 'KarieraController@index')->name('kariera');
Route::get('/kontakt', 'KontaktController@index')->name('kontakt');
Route::get('/oferta', 'OfertaController@index')->name('oferta');
Route::get('/onas', 'MainController@index')->name('onas');
Route::get('/pobranie', 'PobranieController@index')->name('pobranie');
Route::get('/rada', 'RadaController@index')->name('rada');
Route::get('/relacje', 'RelacjeController@index')->name('relacje');
Route::get('/stacja', 'StacjaController@index')->name('stacja');
Route::get('/stacje', 'StationController@index')->name('stacje');
Route::get('/wspieramy', 'WspieramyController@index')->name('wspieramy');
Route::get('/zarzad', 'ZarzadController@index')->name('zarzad');
Route::get('/certyfikaty', 'CertyfikatyController@index')->name('certyfikaty');
Route::get('/galeria', 'GaleriaController@index')->name('galeria');

});

Route::group(['prefix' => 'admin'], function () {
    Voyager::routes();
});

1 个答案:

答案 0 :(得分:0)

这部分代码是错误的:

<?php echo e(route('{{$flip->getTranslatedAttribute('opis')); ?>

您已经在PHP上下文中,而不是刀片服务器,因此不需要大括号({{}})。如果您使用的是像PHPStorm这样的IDE,它会指出该错误。

应该是(PHP上下文):

 <?php echo e(route($flip->getTranslatedAttribute('opis'))); ?>

或(刀片上下文):

    {!! e(route($flip->getTranslatedAttribute('opis'))) !!}