Adding a Prefix to Existing URLs in Laravel 5

Problem: I implement the localization function in my web application, but the application is in the middle of development, so in order not to rewrite all the links in <form action="">and <a href="">, I need a solution that would just add prefix tu URLs before all other routes, such as / en / or / es /, but this application will consider / localhost / en / as localhost /.

To clear the link, for example, it <a href="/admin">works as advertised http: // localhost / admin , I need it to work as http: // localhost / en / admin

I don’t know which code fragments are of any help, so I’ll add the code on request.

route.php looks something like this:

<?php

Route::get('/', 'HomeController@index');
Route::get('admin/blocks/{size}', "AdminController@getBlocks");
Route::get('admin/del-block/{id}', "AdminController@getDelBlock");


Route::controllers([
    'admin' => 'AdminController',
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
    'products' => 'ProductsController'
]);
Route::get('/{slug}', "HomeController@getPage");
Route::get('/{slug}/{subslug}', "HomeController@getPage");

and in the views i create the urls manually

<a href="/admin/blocks{{$block->size}}">Link</a>
<form action="/products/new" > </form>
+4
1

, http://localhost/admin http://localhost/en/admin , 2 routes.php.

, ​​ .

URL: /admin. : {lang}/admin.

+1

All Articles