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
|
|
|
'global' => [ |
47
|
1 |
|
'namespace' => '', |
48
|
1 |
|
], |
49
|
|
|
|
50
|
|
|
'site' => [ |
51
|
1 |
|
'domain' => config('app.domains.site'), |
52
|
1 |
|
'middleware' => 'web', |
53
|
1 |
|
], |
54
|
|
|
|
55
|
|
|
'admin' => [ |
56
|
1 |
|
'domain' => config('app.domains.admin'), |
57
|
1 |
|
'middleware' => 'web', |
58
|
1 |
|
], |
59
|
|
|
|
60
|
|
|
'api' => [ |
61
|
1 |
|
'domain' => config('app.domains.api'), |
62
|
1 |
|
'middleware' => 'api', |
63
|
1 |
|
], |
64
|
|
|
|
65
|
|
|
'api-web' => [ |
66
|
1 |
|
'domain' => config('app.domains.site'), |
67
|
1 |
|
'prefix' => 'api', |
68
|
1 |
|
'namespace' => 'Site', |
69
|
1 |
|
'middleware' => ['web', 'api.client'], |
70
|
1 |
|
], |
71
|
1 |
|
]; |
72
|
|
|
|
73
|
1 |
|
foreach ($routes as $identifier => $attributes) { |
74
|
1 |
|
$attributes['namespace'] = rtrim($this->namespace.'\\'.studly_case(array_get($attributes, 'namespace', $identifier)), '\\'); |
75
|
|
|
|
76
|
1 |
|
Route::group($attributes, function () use ($identifier) { |
77
|
1 |
|
require base_path('routes/'.$identifier.'.php'); |
78
|
1 |
|
}); |
79
|
1 |
|
} |
80
|
1 |
|
} |
81
|
|
|
} |
82
|
|
|
|