How to transfer routes to Laravel?

Based on this question , I am trying to translate routes in Laravel 4.2 in English and Spanish.

This is my application code /routes.php:

<?php


/*Set up locale and locale_prefix if other language is selected*/
if (in_array(Request::segment(1), Config::get('app.web_config.alt_langs'))) {

    App::setLocale(Request::segment(1));
    Config::set('app.web_config.locale_prefix', Request::segment(1));
}


foreach(Lang::get('routes') as $k => $v) {
    Route::pattern($k, $v);
}

Route::group(array('prefix' => Config::get('app.web_config.locale_prefix')), function()
{
    Route::get('/{revelar_fotos}/',['as' => 'revelado_online', 'uses' => 'WebController@reveladoOnline'], function(){
        return 'pages.revelado_online'.App::getLocale();
    });

});

By clicking on the link, I get this error in the URL:

http://mywebsite.dev/%7Brevelar_fotos%7D

Instead:

http://mywebsite.dev/photograph-development

This is my en / routes.php:

<?php

return array(

    'revelar_fotos' => 'photograph-development',
);

And this is my es / routes.php:

<?php

return array(

    'revelar_fotos' => 'revelado-online',
);

Why did I return this error?

+4
source share
1 answer

I understand that the problem is creating URLs http://mywebsite.dev/%7Brevelar_fotos%7D

In this question, you just described how you set up routing processing, and that might work. However, the link itself is generated somewhere else, and you did not make a replacement there.

URL::to(trans("revelar_fotos"));

trans("revelar_fotos") , URL::to() .

+1

Source: https://habr.com/ru/post/1584829/


All Articles