Support the ongoing development of Laravel.io →
posted 10 years ago
Architecture
Last updated 2 years ago.

parisan liked this thread

1

I personally put them in sub-folders. So I would have the following:

app/controllers/User/DashboardController.php

class UserDashboardController extends Controller {

    public function index() {
        return View::make('user.index');
    }

}

app/controllers/Admin/DashboardController.php

class AdminDashboardController extends Controller {

    public function index() {
        return View::make('admin.index');
    }

}

And so on.. Then your routes.php would look like:

Route::get('users/dashboard', 'UserDashboardController@index');
Route::get('admin/dashboard', 'AdminDashboardController@index');

A TIP: When doing this, you may need to run composer dump-autoload for Laravel routes to load your controllers when putting them into sub-folders.

Hopefully that helps or gets you going in the right direction.

Last updated 2 years ago.
0

Nice solution.

PS: There is some info about it in the documentation (4.2) ?

Last updated 2 years ago.

engrjunaidali liked this reply

1

grindmodeon; I'm creating a website in english and spanish, but they will have completely diferent information so the translation package will not be useful. My question is: as you use diferent folder for each controller, do I have to use different folder for each language? like: app/views/spa/Users/index.blade.php for spanish and app/controllers/eng/Users/index.blade.php for the english?

Thanks a lot for your support,

Best Regards,

Last updated 2 years ago.
0

I haven't tested this but I imagine something like this could work

//defined elsewhere
$langAbbreviations = ['en', 'sp', 'io'];


//routes.php
Route::pattern('lang',  implode('|', $langAbbreviations));

Route::group(array('prefix' => '{lang?}'), function()
{
  //define routes

});

//the correct lang prefix can then be detected by
$lang = Route::input('lang');

//which you might use in a language service which can handle language specific operations.
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

mohd-bh mohd-bh Joined 26 Jul 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.