|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; |
|
6
|
|
|
use Illuminate\Support\Facades\Route; |
|
7
|
|
|
|
|
8
|
|
|
class RouteServiceProvider extends ServiceProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* This namespace is applied to your controller routes. |
|
12
|
|
|
* |
|
13
|
|
|
* In addition, it is set as the URL generator's root namespace. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $namespace = 'App\Http\Controllers'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Define your route model bindings, pattern filters, etc. |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function boot() |
|
25
|
|
|
{ |
|
26
|
1 |
|
$this->pattern('id', '[0-9]+'); |
|
27
|
|
|
|
|
28
|
|
|
$this->bind('admin_user', function ($value) { |
|
29
|
|
|
return \App\Models\AdminUser::find($value); |
|
30
|
1 |
|
}); |
|
31
|
|
|
|
|
32
|
1 |
|
parent::boot(); |
|
33
|
1 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Define the routes for the application. |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
1 |
|
public function map() |
|
41
|
|
|
{ |
|
42
|
|
|
// Defines all routes in format: `identifier => attributes`. |
|
43
|
|
|
// If there is no "namespace" in attributes, the default namespace will be `$this->namespace.'\\'.studly_case($identifier)`. |
|
44
|
|
|
// The routes definitions will be placed in file "routes/{$identifer}.php". |
|
45
|
|
|
$routes = [ |
|
46
|
1 |
|
'admin' => [ |
|
47
|
1 |
|
'domain' => config('app.domains.admin'), |
|
48
|
1 |
|
'middleware' => 'web', |
|
49
|
|
|
], |
|
50
|
|
|
|
|
51
|
|
|
'api' => [ |
|
52
|
1 |
|
'domain' => config('app.domains.api'), |
|
53
|
1 |
|
'middleware' => 'api', |
|
54
|
|
|
], |
|
55
|
|
|
|
|
56
|
|
|
'app' => [ |
|
57
|
1 |
|
'domain' => config('app.domains.site'), |
|
58
|
1 |
|
'prefix' => 'm', |
|
59
|
|
|
'middleware' => ['web', 'api.client'], |
|
60
|
|
|
], |
|
61
|
|
|
|
|
62
|
|
|
'site' => [ |
|
63
|
1 |
|
'domain' => config('app.domains.site'), |
|
64
|
1 |
|
'middleware' => 'web', |
|
65
|
|
|
], |
|
66
|
|
|
]; |
|
67
|
|
|
|
|
68
|
1 |
|
foreach ($routes as $identifier => $attributes) { |
|
69
|
1 |
|
$attributes['namespace'] = rtrim($this->namespace.'\\'.studly_case(array_get($attributes, 'namespace', $identifier)), '\\'); |
|
70
|
|
|
|
|
71
|
1 |
|
Route::group($attributes, function () use ($identifier) { |
|
72
|
1 |
|
require base_path('routes/'.$identifier.'.php'); |
|
73
|
1 |
|
}); |
|
74
|
|
|
} |
|
75
|
1 |
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|