Support the ongoing development of →
posted 9 years ago
Last updated 1 year ago.

How big are the articles? Could you set the DB like this:

eng_slug   |   pol_slug  |  eng_title  |  pol_title  | eng_content  |  pol_content  |  eng_seo_title  |  pol_seo_title

You could the query based on segment(1) - eng or pol etc and pull out the correct data.

This approach makes it a little harder to add additional languages harder, but could be OK if you have a limited list. Probably not the right way to go.

Another approach - Which will probably be a bit of a pain - is to have a DB for each language and change the connection to the DB based on the segment(1).

$users = DB::connection(Request::segment(1))->select(...);

Or, you could use segment(1) to query the correct table:

Articles::where(Request::segment(1) . "_articles", $slug)->first();

As a side note, you might be better off using ISO standard slugs to define your locales. Search engines will like you for you.

eng = en or en-gb or en-us pol = pl

Hope that helps a little.

Last updated 1 year ago.

With 16 languages in mind i would end with 48 columns there (minimal version with title, seo_title and content) so thats not the best way imho.

Thanks for the comments with ISO standards I wasnt sure if search engines prioretize such convention. That will come in handy for sure.

This is what im testing right now: What do You think?

(the code below does not handle empty language yet, I know that)

    function ($languageCode = 'pl', $category, $title = '') {
        $languageId = DB::table('languages')->where('abbreviation', $languageCode)->lists(

        if (isset($languageId[$languageCode])) {
            Session::put('languageId', $languageId[$languageCode]);

        $categoryId = DB::table('categories_translations')->where('language_id', App::getLocale())->where(
        )->lists('category_id', 'url');
        $articleId = DB::table('articles_translations')->where('language_id', App::getLocale())->where(
        )->lists('article_id', 'url');

        if ($categoryId && $articleId) {
            return App::make("CategoryController")->viewArticle($categoryId, $articleId);
        } elseif ($categoryId && !$title) {
            return App::make("CategoryController")->listArticles($categoryId);
        } elseif ($categoryId && $title && !$articleId) {
            //We can just throw error that there is no such article
        } else {
            //We can just throw error that there is no such category
Last updated 1 year ago.

I'm using this package works great. Create a translatable model for your pages, posts, etc and look them up in the router:

Route::get('{slug?}', array('uses' => 'SomeController@index'))->where('slug', '.*');
Last updated 1 year ago.

Sign in to participate in this thread!


Your banner here too?

Uriziel01 uriziel01 Joined 1 Oct 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.