1
|
|
|
<?php namespace App\Providers; |
2
|
|
|
|
3
|
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; |
4
|
|
|
use Illuminate\Routing\Router; |
5
|
|
|
|
6
|
|
|
class RouteServiceProvider extends ServiceProvider |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* This namespace is applied to the controller routes in your routes file. |
10
|
|
|
* |
11
|
|
|
* In addition, it is set as the URL generator's root namespace. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $namespace = 'App\Http\Controllers'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Define your route model bindings, pattern filters, etc. |
19
|
|
|
* |
20
|
|
|
* @param \Illuminate\Routing\Router $router |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
30 |
|
public function boot(Router $router) |
25
|
|
|
{ |
26
|
30 |
|
$router->patterns([ |
27
|
30 |
|
'provider' => 'twitter|google|facebook', |
28
|
|
|
'token' => '[a-zA-Z0-9]+' |
29
|
30 |
|
]); |
30
|
|
|
|
31
|
30 |
|
parent::boot($router); |
32
|
30 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Define the routes for the application. |
36
|
|
|
* |
37
|
|
|
* @param \Illuminate\Routing\Router $router |
38
|
|
|
*/ |
39
|
30 |
|
public function map(Router $router) |
40
|
|
|
{ |
41
|
|
|
//----------------------------------------------------------------------- |
42
|
|
|
// Non-localized, generic routes (such as those for admin panel etc). |
43
|
|
|
//----------------------------------------------------------------------- |
44
|
|
|
|
45
|
|
|
$router->group(['namespace' => $this->namespace], function (Router $router) { |
46
|
30 |
|
$router->get('/oauth/{provider}', 'Users\AuthController@getOAuth'); |
47
|
|
|
|
48
|
30 |
|
$router->controllers([ |
49
|
30 |
|
'/admin' => 'AdminController', |
50
|
|
|
'/admin-demo' => 'Admin\DemoController' |
51
|
30 |
|
]); |
52
|
30 |
|
}); |
53
|
|
|
|
54
|
|
|
//----------------------------------------------------------------------------------------------------- |
55
|
|
|
// Register localized routes with locale-prefices (in case of default locale, no prefix is attached). |
56
|
|
|
//----------------------------------------------------------------------------------------------------- |
57
|
|
|
|
58
|
30 |
|
$defaultLocale = config('app.locale'); |
59
|
30 |
|
$namespace = $this->namespace; |
60
|
30 |
|
$middleware = 'locale'; |
61
|
30 |
|
foreach (config('app.locales') as $prefix => $localeName) { |
62
|
30 |
|
app('translator')->setLocale($prefix); |
63
|
|
|
// Skip default locale for now. |
64
|
30 |
|
if ($prefix === $defaultLocale) { |
65
|
30 |
|
continue; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// Set localized routers. |
69
|
|
|
$router->group(compact('namespace', 'middleware', 'prefix'), function (Router $router) use ($prefix) { |
70
|
30 |
|
$this->localizedRoutes($router, $prefix); |
71
|
30 |
|
}); |
72
|
30 |
|
} |
73
|
|
|
|
74
|
|
|
//------------------------------------------------ |
75
|
|
|
// Default locale? No prefices are necessary. |
76
|
|
|
//------------------------------------------------ |
77
|
|
|
|
78
|
30 |
|
app('translator')->setLocale($defaultLocale); |
79
|
30 |
|
$router->group(compact('namespace'), function (Router $router) use ($defaultLocale) { |
80
|
30 |
|
$this->localizedRoutes($router, $defaultLocale); |
81
|
30 |
|
}); |
82
|
30 |
|
} |
83
|
|
|
|
84
|
30 |
|
protected function localizedRoutes(Router $router, $prefix) |
85
|
|
|
{ |
86
|
30 |
|
$router->get('login/{provider?}', ['uses' => 'Users\AuthController@getLogin', 'as' => $prefix . '.login']); |
87
|
30 |
|
$router->post('login/{provider?}', 'Users\AuthController@postLogin'); |
88
|
30 |
|
$router->get('logout', ['uses' => 'Users\AuthController@getLogout', 'as' => $prefix . '.logout']); |
89
|
30 |
|
$router->get('register', ['uses' => 'UsersController@create', 'as' => $prefix . '.register']); |
90
|
30 |
|
$router->post('register', 'UsersController@store'); |
91
|
|
|
|
92
|
30 |
|
$router->resource('users', 'UsersController'); |
93
|
30 |
|
$router->controller('password', 'Users\PasswordController'); |
94
|
30 |
|
$router->controller('activation', 'Users\ActivationController'); |
95
|
|
|
|
96
|
30 |
|
$router->resource('files', 'FilesController', ['only' => ['index', 'create', 'store', 'show', 'destroy']]); |
97
|
|
|
|
98
|
30 |
|
$router->controller('/', 'HomeController'); |
99
|
30 |
|
} |
100
|
|
|
} |
101
|
|
|
|