4

The Problem: I am implementing a localization feature in my web application, but the application is in mid-development, so to not rewrite all the links in <form action=""> and <a href=""> I need a solution that would just add a prefix tu URLs before all other routes like /en/ or /es/, but that Application would consider /localhost/en/ as localhost/.

To clearify link like <a href="/admin"> is working as advertised http://localhost/admin, I need it to work like http://localhost/en/admin

I dont know what pieces of code is any help, so I will add 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 views I generate URLs by hand

<a href="/admin/blocks{{$block->size}}">Link</a>
<form action="/products/new" > </form>
3
  • Here is a good example to add localization laracasts.com/discuss/channels/tips/… Commented Apr 21, 2015 at 8:41
  • @KamranAdil did all that, that doesn't help, all routes are still broken Commented Apr 21, 2015 at 8:52
  • You have to provide more info. What have you tried? Show us your routes file and how you generate your URL's on your views. Commented Apr 21, 2015 at 10:26

1 Answer 1

1

If you want http://localhost/admin and http://localhost/en/admin to be handled by same controllers then you need to write 2 sets of routes in routes.php.

This way there are 2 entry points to exactly same application logic.

First entry point for non-localized url: /admin. Second would take a parameter: {lang}/admin.

Sign up to request clarification or add additional context in comments.

1 Comment

but /en/ could be any of ISO 2 character country codes, it is not logical, that I would need X sets of routes??? and if languages ar added dynamicaly, then its not even possible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.