Laravel路线翻译问题

时间:2016-11-30 19:39:04

标签: php laravel routing

这是一个非常奇怪的情况。我的一些路线不想被翻译。我使用的是Laravel mcamara / laravel-localization包。

路线按照文档中的说明进行翻译。 在我的网站上,每个翻译都有一个标志来改变语言。通过将鼠标悬停在标志上,它仅更改语言,但不会转换路径。奇怪的是,对于某些路线它是有效的,但对于一些不行,我无法找出逻辑是什么。

例如,我有一个用于显示文章的控制器。以下是路线:

<?PHP
$A = "localhost"; // Server Name
$B = "root";      // MySQL Username
$C = "";          // MySQL Password
$D = "sql";       // Database

$CONNECT = new mysqli($A, $B, $C, $D);

if ($CONNECT->connect_error) {
    die("Connection Failed");
}

echo "Connected";

$SQL = "INSERT INTO Images (ID, Image) VALUES (1,LOAD_FILE('1.jpg'))";

if (mysqli_query($CONNECT, $SQL)) {
    echo "Image Sent";
} else {
    echo "Error Sending Image";
}
?>

这里没有翻译路线?

通过悬停我只看到:

Route::get(LaravelLocalization::transRoute('routes.artciles').'/{id}/{slug}.html', ['as' => 'strategy.show', 'uses' => 'ArticlesController@show']); Route::get(LaravelLocalization::transRoute('routes.artciles').'/{category}.html', ['as' => 'strategy.category', 'uses' => 'ArticlesController@category']); Route::get(LaravelLocalization::transRoute('routes.artciles').'.html', ['as' => 'strategy.index', 'uses' => 'ArticlesController@index']); en/articles.html代替de/articles.html en/articles.html

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。这是针对有类似问题的人:

在Http / routes.php中,代码必须没有参数:

Route::get(LaravelLocalization::transRoute('routes.article'), ['as' => 'strategy.show', 'uses' => 'ArticlesController@show'])->where(['id' => '[0-9]+']);
Route::get(LaravelLocalization::transRoute('routes.article_cat'), ['as' => 'strategy.category', 'uses' => 'ArticlesController@category']);
Route::get(LaravelLocalization::transRoute('routes.articles'), ['as' => 'strategy.index', 'uses' => 'ArticlesController@index']);

在lang / routes.php中你可以包含如下参数:

'articles' => 'help.html',
'article' => 'help/{id}/{slug}.html',
'article_cat' => 'help/{category}.html',