├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── resources
└── views
│ ├── help.blade.php
│ └── output.blade.php
├── routes
└── web.php
├── src
├── Console
│ ├── Builder.php
│ ├── Cmd.php
│ ├── Installer.php
│ ├── Router.php
│ ├── Seeder.php
│ └── StringOutput.php
├── Http
│ └── Controllers
│ │ └── LaADuoController.php
├── LaADuoExt.php
├── LaADuoServiceProvider.php
├── Middleware
│ ├── AdminGuards.php
│ ├── Authenticate.php
│ └── Prefix.php
└── Models
│ └── Migration.php
└── stubs
├── AuthController.stub
├── config.stub
└── extroutes.stub
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | phpunit.phar
3 | /vendor
4 | composer.phar
5 | composer.lock
6 | *.project
7 | .idea/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Jens Segers
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #### 现在不怎使用`laravel`和`laravel-admin`了,遇到问题我未必能帮到你,如果你打算使用此扩展,需要有一定的解决问题能力。如果你解决了什么问题,欢迎提交pr
2 |
3 | # laravel-admin la-a-duo
4 |
5 | ## Installation
6 |
7 | Run :
8 |
9 | ```
10 | $ composer require ichynul/la-a-duo
11 | ```
12 |
13 | Then run:
14 |
15 | ```
16 | $ php artisan admin:import la-a-duo
17 | ```
18 |
19 | ## Config
20 |
21 | Add a config in `config/admin.php`:
22 |
23 | ```php
24 | 'extensions' => [
25 | 'la-a-duo' => [
26 | // Set to `false` if you want to disable this extension
27 | 'enable' => true,
28 | // ['admin1' ,'admin2' , ...]
29 | 'prefixes' => ['admin1'],
30 | // Set to `false` allow login to different prefixes in same brower
31 | 'apart' => true,
32 | // Set to `true` allow extend routes from base admin , Such as http://localhost/admin1/goods => Admin\Controllers\GoodsController@index
33 | 'extend_routes' => false,
34 | // Base admin_tables migration file path, if new prefix use different database setting , copy this file for it
35 | 'base_migration' => database_path('migrations/2016_01_04_173148_create_admin_tables.php')
36 | ]
37 | ],
38 |
39 | ```
40 |
41 | ## Usage
42 |
43 | Open `http://your-host/admin/la-a-duo`
44 |
45 | After this it will create files in `/app/admin1` and create config file `/config/admin1.php`
46 |
47 | Then open `http://your-host/admin1`
48 |
49 | ## Commonds
50 |
51 | `$ php artisan laaduo:{action} {prefix?}`
52 |
53 | If no prefix, for all
54 |
55 | `$ php artisan laaduo:install admin1`
56 |
57 | Create `/app/Admin1` dir and create routes.php and controllers
58 |
59 | `$ php artisan laaduo:route admin1`
60 |
61 | Create `/app/Admin1/extroutes.php`
62 |
63 | `$ php artisan laaduo:build admin1`
64 |
65 | Create `/database/migrations/admin1/2016_01_04_173148_create_admin_tables_admin1.php` and `migrate`.
66 |
67 | `$ php artisan laaduo:seed admin1`
68 |
69 | Seed `AdminTablesSeeder` seed admin tables(users,rols,menus...), if table is not empty, will pass it
70 |
71 | ---
72 |
73 | Licensed under [The MIT License (MIT)](LICENSE).
74 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ichynul/la-a-duo",
3 | "description": "laravel-admin 后台多开",
4 | "type": "library",
5 | "keywords": ["laravel-admin", "extension"],
6 | "homepage": "https://github.com/ichynul/la-a-duo",
7 | "license": "MIT",
8 | "authors": [
9 | {
10 | "name": "ichynul",
11 | "email": "ichynul@outlook.com"
12 | }
13 | ],
14 | "require": {
15 | "php": ">=7.0.0",
16 | "encore/laravel-admin": "~1.6"
17 | },
18 | "require-dev": {
19 | "phpunit/phpunit": "~6.0"
20 | },
21 | "autoload": {
22 | "psr-4": {
23 | "Ichynul\\LaADuo\\": "src/"
24 | }
25 | },
26 | "extra": {
27 | "laravel": {
28 | "providers": [
29 | "Ichynul\\LaADuo\\LaADuoServiceProvider"
30 | ]
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/resources/views/help.blade.php:
--------------------------------------------------------------------------------
1 |
2 | install
: Create `/app/$prefix` dir and create routes.php and controllers
3 | route
: Create `/app/$prefix/extroutes.php`
4 | build
: Create `/database/migrations/$prefix/2016_01_04_173148_create_admin_tables_$prefix.php` and `migrate`.
5 | seed
: Seed `AdminTablesSeeder` seed admin tables(users,rols,menus...), if table is not empty, will pass it
6 |
--------------------------------------------------------------------------------
/resources/views/output.blade.php:
--------------------------------------------------------------------------------
1 | @if($lines)
2 |
3 | @foreach($lines as $line)
4 | {!! $line !!}
5 | @endforeach
6 |
7 | @endif
--------------------------------------------------------------------------------
/routes/web.php:
--------------------------------------------------------------------------------
1 | line('prefixes not seted ,pleace edit config in `config/admin.php`');
46 |
47 | return;
48 | }
49 |
50 | if ($this->input) {
51 |
52 | $currentPrefix = $this->argument('prefix');
53 |
54 | if ($currentPrefix && $currentPrefix != 'all') {
55 |
56 | if (!in_array($currentPrefix, $prefixes)) {
57 |
58 | $this->line("prefix $currentPrefix dose not exists !");
59 | return;
60 | }
61 |
62 | try {
63 |
64 | $this->prefix($currentPrefix);
65 | } catch (\Exception $e) {
66 | $this->line("" . $e->getMessage() . "");
67 | }
68 |
69 | return;
70 | }
71 | }
72 |
73 | if (!$this->laravel->runningInConsole()) {
74 | $this->line("php artisan laaduo:build all");
75 | }
76 |
77 | foreach ($prefixes as $prefix) {
78 |
79 | try {
80 | $this->prefix($prefix);
81 |
82 | $this->line('*********************************************************************');
83 | } catch (\Exception $e) {
84 | $this->line("" . $e->getMessage() . "");
85 | }
86 | }
87 | }
88 |
89 | /**
90 | * Update migrations for current prefix when running in console
91 | *
92 | * init migrate for another database setting
93 | *
94 | * @param [type] $prefix
95 | * @return void
96 | */
97 | public function prefix($prefix)
98 | {
99 | $this->line("{$this->description}:{$prefix}");
100 |
101 | if (!$this->dbConfigOld) {
102 | $this->dbConfigOld = config('admin.database');
103 | }
104 |
105 | if (!$this->base_migration) {
106 | $this->base_migration = LaADuoExt::config('base_migration', database_path('migrations/2016_01_04_173148_create_admin_tables.php'));
107 | }
108 |
109 | $dbConfigCurrent = config("{$prefix}.database", []);
110 |
111 | if (empty($dbConfigCurrent)) {
112 |
113 | $this->line("Database configs not seted ,pleace edit config in `config/{$prefix}.php`");
114 |
115 | return;
116 | }
117 |
118 | $contents = app('files')->get($this->base_migration);
119 |
120 | $watchTables = [
121 | 'users_table', 'roles_table', 'permissions_table',
122 | 'menu_table', 'role_users_table', 'role_permissions_table',
123 | 'user_permissions_table', 'role_menu_table', 'operation_log_table',
124 | ];
125 |
126 | /**
127 | * Connection is same check tables diffrence
128 | */
129 | if (Arr::get($dbConfigCurrent, 'connection') == Arr::get($this->dbConfigOld, 'connection')) {
130 |
131 | $newTables = [];
132 |
133 | foreach ($watchTables as $table) {
134 |
135 | if (Arr::get($dbConfigCurrent, $table) == Arr::get($this->dbConfigOld, $table)) {
136 | continue;
137 | }
138 |
139 | if (empty(Arr::get($dbConfigCurrent, $table))) {
140 | continue;
141 | }
142 |
143 | $newTables[] = $table;
144 |
145 | $this->line("`{$table}` : " . Arr::get($dbConfigCurrent, $table) . " New");
146 | }
147 |
148 | unset($table);
149 |
150 | $noChangeTables = array_diff($watchTables, $newTables);
151 |
152 | foreach ($noChangeTables as $table) {
153 | // up
154 | $contents = preg_replace("/Schema::[^\}]+?\." . $table . "[\"'][^\}]+?\}\s*\)\s*;/s", "/*Table name : $table no change*/", $contents);
155 | // down
156 | $contents = preg_replace("/Schema::[^;]*?dropIfExists[^;]+?\." . $table . "[\"'][^;]+?;/", "/*Table name : $table no change*/", $contents);
157 |
158 | $this->line("`{$table}` : " . Arr::get($dbConfigCurrent, $table) . " No change");
159 | }
160 |
161 | unset($table);
162 |
163 | foreach ($newTables as $table) {
164 | $contents = preg_replace("/Schema::[^\}]+?\." . $table . "[\"'][^\}]+?\}\s*\)\s*;/s", "if (!Schema::hasTable(config('admin.database.$table'))){" . PHP_EOL . " $0/*tableend*/}", $contents);
165 | }
166 |
167 | $contents = preg_replace('/\$table\->/', ' $0', $contents);
168 |
169 | $contents = preg_replace('/(\}\);)\/\*tableend\*\/(\})/', ' $1' . PHP_EOL . ' $2', $contents);
170 |
171 | if (count($newTables) == 0) {
172 |
173 | return;
174 | }
175 | } else {
176 |
177 | $this->line("Database connection changed:" . Arr::get($dbConfigCurrent, 'connection'));
178 |
179 | foreach ($watchTables as $table) {
180 | $this->line("`{$table}` " . Arr::get($dbConfigCurrent, $table) . " OK");
181 | }
182 | }
183 |
184 | $migrations = preg_replace('/migrations[\/\\\]/', "migrations/{$prefix}/", $this->base_migration);
185 |
186 | $migrations = preg_replace('/\.php$/', "_{$prefix}.php", $migrations);
187 |
188 | $contents = preg_replace("/admin\.database\./", "{$prefix}.database.", $contents);
189 |
190 | $contents = preg_replace("/class \w+ extends/i", "class CreateAdminTables" . ucfirst($prefix) . " extends", $contents);
191 |
192 | if (!is_dir(dirname($migrations))) {
193 |
194 | $this->laravel['files']->makeDirectory(dirname($migrations), 0755, true, true);
195 | }
196 |
197 | $this->laravel['files']->put(
198 | $migrations,
199 | $contents
200 | );
201 |
202 | $this->line('Migrations file was created: ' . str_replace(base_path(), '', $migrations));
203 |
204 | $this->migrate($migrations);
205 | }
206 |
207 | protected function migrate($path)
208 | {
209 | $migration = preg_replace('/.+[\/\\\](.+)\.php$/', '$1', $path);
210 |
211 | $path = str_replace(base_path() . DIRECTORY_SEPARATOR, '', dirname($path));
212 |
213 | $path = preg_replace('/\\\/', '/', $path);
214 |
215 | $this->line("php artisan migrate --path={$path}");
216 |
217 | $migrate = Migration::where('migration', $migration)->first();
218 |
219 | if ($migrate) {
220 | $this->line('Delete migration info:' . json_encode($migrate) . '');
221 |
222 | $migrate->delete();
223 | }
224 |
225 | if ($this->laravel->runningInConsole()) {
226 | $this->call('migrate', ['--path' => $path]);
227 | } else {
228 |
229 | // If Exception raised.
230 | if (1 === Artisan::handle(
231 | new ArgvInput(explode(' ', "artisan migrate --path={$path}")),
232 | $output = new StringOutput()
233 | )) {
234 |
235 | $lines = collect($output->getLines())->map(function ($line) {
236 | return "$line";
237 | })->all();
238 |
239 | $this->lines = array_merge($this->lines, $lines);
240 | } else {
241 | $this->lines = array_merge($this->lines, $output->getLines());
242 | }
243 | }
244 | }
245 | }
246 |
--------------------------------------------------------------------------------
/src/Console/Cmd.php:
--------------------------------------------------------------------------------
1 | laravel) {
23 | $this->laravel = app();
24 | }
25 |
26 | if (!$this->output) {
27 | $this->output = new StringOutput();
28 | }
29 | }
30 |
31 | /**
32 | * Write a string as html.
33 | *
34 | * @param string $string
35 | * @param string $style
36 | * @param int|string|null $verbosity
37 | * @return void
38 | */
39 | public function line($string, $style = null, $verbosity = null)
40 | {
41 | $this->lines[] = $string;
42 |
43 | $string = preg_replace('/<(\w+)[^<>]*>/', '<$1>', $string);
44 |
45 | $string = preg_replace('/<(\/?)(?!(info|question|error|warn))[^<>]+>/i', '<$1info>', $string);
46 |
47 | parent::line($string, $style, $verbosity);
48 | }
49 |
50 | public function getLines()
51 | {
52 | return collect($this->lines)->map(function ($line) {
53 |
54 | $line = preg_replace('/]*)>/i', '', $line);
55 |
56 | $line = preg_replace('/]*)>/i', '', $line);
57 |
58 | $line = preg_replace('/]*)>/i', '', $line);
59 |
60 | $line = preg_replace('/]*)>/i', '', $line);
61 |
62 | $line = preg_replace('/<\/(info|question|error|warn)[^<>]*>/i', '', $line);
63 |
64 | if (preg_match('/php\s*artisan\s/i', $line)) {
65 | $line = "$line";
66 | }
67 |
68 | return '$ ' . $line;
69 | })->all();
70 | }
71 |
72 | protected function checkFiles($prefix)
73 | {
74 | $bootstrapFile = $this->directory . DIRECTORY_SEPARATOR . 'bootstrap.php';
75 | $routesFile = $this->directory . DIRECTORY_SEPARATOR . "routes.php";
76 | $extRoutesFile = $this->directory . DIRECTORY_SEPARATOR . "extroutes.php";
77 | $configFile = LaADuoExt::getConfigPath($prefix);
78 |
79 | if (is_dir($this->directory . DIRECTORY_SEPARATOR . 'Controllers')) {
80 | $path = str_replace(base_path(), '-', $this->directory . DIRECTORY_SEPARATOR . 'Controllers');
81 |
82 | $this->line("{$path} OK");
83 | } else {
84 | $path = str_replace(base_path(), '-', $this->directory . DIRECTORY_SEPARATOR . 'Controllers');
85 |
86 | $this->line("{$path} MISS");
87 | }
88 |
89 | $this->fileInfo($bootstrapFile);
90 | $this->fileInfo($routesFile);
91 | $this->fileInfo($extRoutesFile);
92 | $this->fileInfo($configFile);
93 | }
94 |
95 | /**
96 | * Check file info
97 | *
98 | * @param [type] $path
99 | * @return void
100 | */
101 | protected function fileInfo($path)
102 | {
103 | if (file_exists($path)) {
104 | $path = str_replace(base_path(), '-', $path);
105 |
106 | $this->line("{$path} OK");
107 | } else {
108 | $path = str_replace(base_path(), '-', $path);
109 |
110 | $this->line("{$path} MISS, will create auto.");
111 | }
112 | }
113 |
114 | /**
115 | * Get stub contents.
116 | *
117 | * @param $name
118 | *
119 | * @return string
120 | */
121 | public function getStub($name)
122 | {
123 | if (in_array($name, ['AuthController', 'config', 'extroutes'])) {
124 | return $this->laravel['files']->get(__DIR__ . "/../../stubs/{$name}.stub");
125 | }
126 |
127 | return $this->laravel['files']->get(base_path("vendor/encore/laravel-admin/src/Console/stubs/{$name}.stub"));
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/src/Console/Installer.php:
--------------------------------------------------------------------------------
1 | line('prefixes not seted ,pleace edit config in `config/admin.php`');
38 |
39 | return;
40 | }
41 |
42 | if ($this->input) {
43 |
44 | $currentPrefix = $this->argument('prefix');
45 |
46 | if ($currentPrefix && $currentPrefix != 'all') {
47 |
48 | if (!in_array($currentPrefix, $prefixes)) {
49 |
50 | $this->line("prefix $currentPrefix dose not exists !");
51 | return;
52 | }
53 |
54 | try {
55 |
56 | $this->prefix($currentPrefix);
57 |
58 | } catch (\Exception $e) {
59 | $this->line("" . $e->getMessage() . "");
60 | }
61 |
62 | return;
63 | }
64 | }
65 |
66 | if (!$this->laravel->runningInConsole()) {
67 | $this->line("php artisan laaduo:install all");
68 | }
69 |
70 | foreach ($prefixes as $prefix) {
71 |
72 | try {
73 | $this->prefix($prefix);
74 |
75 | $this->line('*********************************************************************');
76 |
77 | } catch (\Exception $e) {
78 | $this->line("" . $e->getMessage() . "");
79 | }
80 | }
81 | }
82 |
83 | public function prefix($prefix)
84 | {
85 | $this->line("{$this->description}:{$prefix}");
86 |
87 | $this->directory = app_path(ucfirst($prefix));
88 |
89 | $basePrefix = config('admin.route.prefix', 'admin');
90 |
91 | if ($prefix == $basePrefix) {
92 |
93 | $this->line("Can't same as laravel-admin base prefix:{$prefix}");
94 | return;
95 | }
96 |
97 | if (!preg_match('/^\w+$/', $prefix)) {
98 |
99 | $this->line("Invalid prefix:{$prefix} ");
100 | return;
101 | }
102 |
103 | if (!is_dir($this->directory)) {
104 |
105 | $this->create($prefix);
106 |
107 | return;
108 | }
109 |
110 | $path = str_replace(base_path(), '', $this->directory);
111 |
112 | if (!$this->laravel->runningInConsole()) {
113 | $url = url($prefix);
114 |
115 | $this->line("{$url}");
116 | }
117 |
118 | $this->line("-{$path}");
119 |
120 | $this->checkFiles($prefix);
121 |
122 | $this->createConfig($prefix);
123 | }
124 |
125 | /**
126 | * Execute the console command.
127 | *
128 | * @return void
129 | */
130 | public function create($prefix)
131 | {
132 |
133 | $baseNamespace = config('admin.route.namespace');
134 |
135 | config([
136 | 'admin.route.namespace' => LaADuoExt::getNamespace($prefix),
137 | ]);
138 |
139 | $this->initAdminDirectory();
140 |
141 | config([
142 | 'admin.route.namespace' => $baseNamespace,
143 | ]);
144 |
145 | $this->createConfig($prefix);
146 |
147 | if ($this->laravel->runningInConsole()) {
148 |
149 | $this->call("laaduo:route", ['prefix' => $prefix]);
150 |
151 | $this->call("laaduo:build", ['prefix' => $prefix]);
152 |
153 | $this->call("laaduo:seed", ['prefix' => $prefix]);
154 | }
155 | }
156 |
157 | /**
158 | * Create config.
159 | *
160 | * @return void
161 | */
162 | public function createConfig($prefix)
163 | {
164 | $configFile = LaADuoExt::getConfigPath($prefix);
165 |
166 | if (file_exists($configFile)) {
167 |
168 | $this->line("Config file exists pass it:" . str_replace(base_path(), '', $configFile));
169 | return;
170 | }
171 |
172 | $contents = $this->getStub('config');
173 |
174 | $contents = preg_replace('/.#auth.controller#./', 'App\\' . ucfirst($prefix) . '\\Controllers\\AuthController::class', $contents);
175 |
176 | $contents = preg_replace('/.#bootstrap#./', "app_path('" . ucfirst($prefix) . "/bootstrap.php')", $contents);
177 |
178 | $this->laravel['files']->put(
179 | $configFile,
180 | $contents
181 | );
182 |
183 | $this->line('Config file was created: ' . str_replace(base_path(), '', $configFile));
184 | }
185 |
186 | /**
187 | * Initialize the admAin directory.
188 | *
189 | * @return void
190 | */
191 | protected function initAdminDirectory()
192 | {
193 | if (is_dir($this->directory)) {
194 | $this->line(" directory already exists ! ");
195 |
196 | return;
197 | }
198 |
199 | $this->makeDir('/');
200 |
201 | $this->line('Admin directory was created: ' . str_replace(base_path(), '', $this->directory));
202 |
203 | $this->makeDir('Controllers');
204 | $this->createHomeController();
205 | $this->createAuthController();
206 | $this->createExampleController();
207 | $this->createBootstrapFile();
208 |
209 | $this->createRoutesFile();
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/src/Console/Router.php:
--------------------------------------------------------------------------------
1 | routeLines;
34 | }
35 |
36 | public function handle()
37 | {
38 | $prefixes = LaADuoExt::config('prefixes', []);
39 |
40 | if (empty($prefixes)) {
41 |
42 | $this->line('prefixes not seted ,pleace edit config in `config/admin.php`');
43 |
44 | return;
45 | }
46 |
47 | $this->getRoutes();
48 |
49 | if ($this->input) {
50 |
51 | $currentPrefix = $this->argument('prefix');
52 |
53 | if ($currentPrefix && $currentPrefix != 'all') {
54 |
55 | if (!in_array($currentPrefix, $prefixes)) {
56 |
57 | $this->line("prefix $currentPrefix dose not exists !");
58 | return;
59 | }
60 |
61 | try {
62 |
63 | $this->prefix($currentPrefix);
64 |
65 | } catch (\Exception $e) {
66 | $this->line("" . $e->getMessage() . "");
67 | }
68 |
69 | return;
70 | }
71 | }
72 |
73 |
74 | if (!$this->laravel->runningInConsole()) {
75 | $this->line("php artisan laaduo:route all");
76 | }
77 |
78 | foreach ($prefixes as $prefix) {
79 |
80 | try {
81 | $this->prefix($prefix);
82 |
83 | $this->line('*********************************************************************');
84 | } catch (\Exception $e) {
85 | $this->line("" . $e->getMessage() . "");
86 | }
87 | }
88 | }
89 |
90 | public function prefix($prefix)
91 | {
92 | $this->line("{$this->description}:{$prefix}");
93 |
94 | $this->directory = app_path(ucfirst($prefix));
95 |
96 | if (!is_dir($this->directory)) {
97 |
98 | $this->line("{$this->directory} directory did not exists ! ");
99 |
100 | return;
101 | }
102 |
103 | $this->createExtRoutes($prefix);
104 | }
105 |
106 | /**
107 | * Create ExtRoutes.
108 | *
109 | * @return void
110 | */
111 | public function createExtRoutes($prefix)
112 | {
113 | $extRoutesFile = $this->directory . DIRECTORY_SEPARATOR . "extroutes.php";
114 |
115 | if (file_exists($extRoutesFile)) {
116 |
117 | $this->line("Extroutes file exists pass it:" . str_replace(base_path(), '', $extRoutesFile));
118 | return;
119 | }
120 |
121 | $contents = $this->getStub('extroutes');
122 |
123 | $contents = preg_replace('/..#routers#/', implode(PHP_EOL . PHP_EOL . ' ', $this->routeLines), $contents);
124 |
125 | $contents = preg_replace('/#Namestar#/', ucfirst($prefix), $contents);
126 |
127 | $contents = preg_replace('/#Time#/', date("Y/m/d h:i:s", time()), $contents);
128 |
129 | $contents = preg_replace('/lad\.prefix:#prefix#/', "lad.prefix:{$prefix}", $contents);
130 |
131 | $contents = preg_replace('/#prefix#/', '', $contents);
132 |
133 | $contents = preg_replace('/#currentAdmin#/', str_replace(base_path(), '', app_path(ucfirst($prefix))), $contents);
134 |
135 | $this->laravel['files']->put(
136 | $extRoutesFile,
137 | $contents
138 | );
139 |
140 | $this->line('Extroutes file was created: ' . str_replace(base_path(), '', $extRoutesFile));
141 | }
142 |
143 | /**
144 | * Get all app routes
145 | *
146 | * @return void
147 | */
148 | public function getRoutes()
149 | {
150 | $routes = app('router')->getRoutes();
151 |
152 | $routes = collect($routes)->map(function ($route) {
153 | return $this->getRouteInformation($route);
154 | })->all();
155 |
156 | $routes = array_filter($routes);
157 |
158 | /**
159 | * create routes
160 | */
161 |
162 | $route = config('admin.route', []);
163 |
164 | $basePrefix = Arr::get($route, 'prefix', 'admin');
165 |
166 | $baseMiddleware = Arr::get($route, 'middleware', []);
167 |
168 | $baseNamespace = Arr::get($route, 'namespace', '');
169 |
170 | $extend_routes = LaADuoExt::config('extend_routes', false);
171 |
172 | foreach ($routes as $route) {
173 |
174 | $action = $route['action'];
175 |
176 | $name = $route['name'];
177 |
178 | $middleware = $route['middleware']->all();
179 |
180 | $namespace = preg_replace('/(.+)\\\[^\\\]+$/', '$1', $action);
181 |
182 | if (preg_match('/Encore\\\Admin\\\Controllers/', $action)) {
183 | continue;
184 | }
185 |
186 | if (!preg_match("/^" . $basePrefix . "/", $route['uri'])) {
187 | continue;
188 | }
189 |
190 | $same = empty(array_diff($middleware, $baseMiddleware)) && $baseNamespace == $namespace;
191 |
192 | $system = preg_match("/" . $basePrefix . "\/auth\/(users|roles|permissions|menu|logs|login|logout|setting)$/", $route['uri']);
193 |
194 | if ($system && $same) {
195 | continue;
196 | }
197 |
198 | if (in_array('admin', $middleware)) {
199 |
200 | if (count($route['method']) == 7) {
201 |
202 | $route['method'] = ['any'];
203 | } else if (in_array('GET', $route['method'])) {
204 |
205 | $route['method'] = ['get'];
206 | }
207 |
208 | $uri = $route['uri'];
209 |
210 | $uri = preg_replace("/^" . $basePrefix . "/", '#prefix#', $uri);
211 |
212 | $name = empty($name) ? "" : "->name('{$name}')";
213 |
214 | $middleware = array_diff($middleware, ['admin', 'web', 'Closure']);
215 |
216 | array_unshift($middleware, 'lad.admin');
217 |
218 | array_unshift($middleware, "lad.prefix:#prefix#");
219 |
220 | array_unshift($middleware, 'web');
221 |
222 | $middle = "->middleware(['" . implode("', '", $middleware) . "'])";
223 |
224 | foreach ($route['method'] as $method) {
225 |
226 | $method = strtolower($method);
227 |
228 | if ($same && !preg_match('/\\\HomeController@/', $action)) {
229 |
230 | if (!$extend_routes) {
231 | $rourstr = "//\$router->{$method}('{$uri}', '$action'){$middle}{$name};";
232 | } else {
233 | $rourstr = "\$router->{$method}('{$uri}', '$action'){$middle}{$name};";
234 | }
235 |
236 | $this->sameNamespaces[] = $rourstr;
237 | } else {
238 |
239 | $rourstr = "\$router->{$method}('{$uri}', '$action'){$middle}{$name};";
240 |
241 | if ($system && $baseNamespace == $namespace) {
242 |
243 | $newNamespace = preg_replace('/^(.?App\\\)\w+(\\\.+$)/', '$1#Namestar#$2', $namespace);
244 |
245 | $rourstr = str_replace($namespace, $newNamespace, $rourstr);
246 | }
247 |
248 | $this->routeLines[] = $rourstr;
249 | }
250 | }
251 | }
252 | }
253 |
254 | if (!empty($this->sameNamespaces && !$extend_routes)) {
255 |
256 | $baseAdmin = str_replace(base_path(), '', admin_path());
257 |
258 | array_unshift($this->sameNamespaces, "*If you want extends all routes from base admin, set config `extend_routes` to 'true' in `/config/admin.php` */");
259 |
260 | array_unshift($this->sameNamespaces, "*Or another way, just copy some routes you want from this file to #currentAdmin#" . DIRECTORY_SEPARATOR . "routes.php");
261 |
262 | array_unshift($this->sameNamespaces, "Then copy controllers from {$baseAdmin}" . DIRECTORY_SEPARATOR . "Controllers to #currentAdmin#" . DIRECTORY_SEPARATOR . "Controllers and edit namespaces of them (bueause prefix changed).");
263 |
264 | array_unshift($this->sameNamespaces, "If you want to use them ,copy routes from {$baseAdmin} to #currentAdmin#.");
265 |
266 | array_unshift($this->sameNamespaces, "/*Routes below were dissabled because they sames extends from base Admin. Such as http://localhost/admin1/goods => Admin\Controllers\GoodsController@index");
267 | }
268 |
269 | $this->routeLines = array_merge($this->routeLines, $this->sameNamespaces);
270 | }
271 |
272 | /**
273 | * Get the route information for a given route.
274 | *
275 | * @param \Illuminate\Routing\Route $route
276 | *
277 | * @return array
278 | */
279 | protected function getRouteInformation($route)
280 | {
281 | return [
282 | 'host' => $route->domain(),
283 | 'method' => $route->methods(),
284 | 'uri' => $route->uri(),
285 | 'name' => $route->getName(),
286 | 'action' => $route->getActionName(),
287 | 'middleware' => $this->getRouteMiddleware($route),
288 | ];
289 | }
290 |
291 | /**
292 | * Get before filters.
293 | *
294 | * @param \Illuminate\Routing\Route $route
295 | *
296 | * @return string
297 | */
298 | protected function getRouteMiddleware($route)
299 | {
300 | return collect($route->gatherMiddleware())->map(function ($middleware) {
301 | return $middleware instanceof \Closure ? 'Closure' : $middleware;
302 | });
303 | }
304 | }
305 |
--------------------------------------------------------------------------------
/src/Console/Seeder.php:
--------------------------------------------------------------------------------
1 | line('prefixes not seted ,pleace edit config in `config/admin.php`');
42 |
43 | return;
44 | }
45 |
46 | if ($this->input) {
47 |
48 | $currentPrefix = $this->argument('prefix');
49 |
50 | if ($currentPrefix && $currentPrefix != 'all') {
51 |
52 | if (!in_array($currentPrefix, $prefixes)) {
53 |
54 | $this->line("prefix $currentPrefix dose not exists !");
55 | return;
56 | }
57 |
58 | try {
59 |
60 | $this->prefix($currentPrefix);
61 |
62 | } catch (\Exception $e) {
63 | $this->line("" . $e->getMessage() . "");
64 | }
65 |
66 | return;
67 | }
68 | }
69 |
70 | if (!$this->laravel->runningInConsole()) {
71 | $this->line("php artisan laaduo:seed all");
72 | }
73 |
74 | foreach ($prefixes as $prefix) {
75 |
76 | try {
77 | $this->prefix($prefix);
78 |
79 | $this->line('*********************************************************************');
80 |
81 | } catch (\Exception $e) {
82 | $this->line("" . $e->getMessage() . "");
83 | }
84 | }
85 | }
86 |
87 | /**
88 | * Install new apps
89 | *
90 | * @return void
91 | */
92 | public function prefix($prefix)
93 | {
94 | $this->line("{$this->description}:{$prefix}");
95 |
96 | $dbConfigCurrent = config("{$prefix}.database", []);
97 |
98 | if (empty($dbConfigCurrent)) {
99 |
100 | $this->line("Nothing to seed for $prefix");
101 | return;
102 | }
103 |
104 | LaADuoExt::overrideConfig($prefix);
105 |
106 | // create a user.
107 | if (!Administrator::count()) {
108 | Administrator::create([
109 | 'username' => 'admin',
110 | 'password' => bcrypt('admin'),
111 | 'name' => 'Administrator',
112 | ]);
113 |
114 | $this->line("Create admin user: admin ");
115 | } else {
116 | $this->line("Admin users table is not empty, pass ");
117 | }
118 |
119 | if (!Role::count()) {
120 | // create a role.
121 | Role::create([
122 | 'name' => 'Administrator',
123 | 'slug' => 'administrator',
124 | ]);
125 |
126 | if (!Administrator::first()->roles()->find(Role::first()->id)) {
127 | Administrator::first()->roles()->save(Role::first());
128 | }
129 |
130 | $this->line("Create role: Administrator ");
131 | } else {
132 | $this->line("Admin roles table is not empty, pass ");
133 | }
134 |
135 | // add role to user.
136 |
137 |
138 | if (!Permission::count()) {
139 |
140 | //create a permission
141 | Permission::insert([
142 | [
143 | 'name' => 'All permission',
144 | 'slug' => '*',
145 | 'http_method' => '',
146 | 'http_path' => '*',
147 | ],
148 | [
149 | 'name' => 'Dashboard',
150 | 'slug' => 'dashboard',
151 | 'http_method' => 'GET',
152 | 'http_path' => '/',
153 | ],
154 | [
155 | 'name' => 'Login',
156 | 'slug' => 'auth.login',
157 | 'http_method' => '',
158 | 'http_path' => "/auth/login\r\n/auth/logout",
159 | ],
160 | [
161 | 'name' => 'User setting',
162 | 'slug' => 'auth.setting',
163 | 'http_method' => 'GET,PUT',
164 | 'http_path' => '/auth/setting',
165 | ],
166 | [
167 | 'name' => 'Auth management',
168 | 'slug' => 'auth.management',
169 | 'http_method' => '',
170 | 'http_path' => "/auth/roles\r\n/auth/permissions\r\n/auth/menu\r\n/auth/logs",
171 | ],
172 | ]);
173 |
174 | if (!Role::first()->permissions()->find(Permission::first()->id)) {
175 | Role::first()->permissions()->save(Permission::first());
176 | }
177 |
178 | $this->line("Create permissions ");
179 | } else {
180 | $this->line("Admin permissions table is not empty, pass ");
181 | }
182 |
183 | // add default menus.
184 | if (!Menu::count()) {
185 | $menus = array(
186 | [
187 | 'title' => 'Dashboard',
188 | 'icon' => 'fa-bar-chart',
189 | 'uri' => '/',
190 | ],
191 | [
192 | 'title' => 'Admin',
193 | 'icon' => 'fa-tasks',
194 | 'uri' => '',
195 | 'sub' => array(
196 | [
197 | 'title' => 'Users',
198 | 'icon' => 'fa-users',
199 | 'uri' => 'auth/users',
200 | ],
201 | [
202 | 'title' => 'Roles',
203 | 'icon' => 'fa-user',
204 | 'uri' => 'auth/roles',
205 | ],
206 | [
207 | 'title' => 'Permission',
208 | 'icon' => 'fa-ban',
209 | 'uri' => 'auth/permissions',
210 | ],
211 | [
212 | 'title' => 'Menu',
213 | 'icon' => 'fa-bars',
214 | 'uri' => 'auth/menu',
215 | ],
216 | [
217 | 'title' => 'Operation log',
218 | 'icon' => 'fa-history',
219 | 'uri' => 'auth/logs',
220 | ]
221 | )
222 | ]
223 | );
224 |
225 | $i = 1;
226 | foreach ($menus as $menu) {
227 | $data = array(
228 | 'parent_id' => 0,
229 | 'order' => $i,
230 | 'title' => $menu['title'],
231 | 'icon' => $menu['icon'],
232 | 'uri' => $menu['uri']
233 | );
234 | $id = Menu::insertGetId($data);
235 | $i += 5;
236 | if (isset($menu['sub'])) {
237 | foreach ($menu['sub'] as $sm) {
238 | $_data = array(
239 | 'parent_id' => $id,
240 | 'order' => $i,
241 | 'title' => $sm['title'],
242 | 'icon' => $sm['icon'],
243 | 'uri' => $sm['uri']
244 | );
245 | Menu::insert($_data);
246 | $i += 5;
247 | }
248 | }
249 | }
250 | Menu::where('id', '>', 0)->update(['created_at' => now(), 'updated_at' => now()]);
251 | // add role to menu.
252 | Menu::find(2)->roles()->save(Role::first());
253 |
254 | $this->line("Create menus ");
255 | } else {
256 | $this->line("Admin menus table is not empty, pass ");
257 | }
258 | }
259 | }
260 |
--------------------------------------------------------------------------------
/src/Console/StringOutput.php:
--------------------------------------------------------------------------------
1 | lines = [];
16 | $this->line = '';
17 | }
18 |
19 | protected function doWrite($message, $newline)
20 | {
21 | $this->line .= $message;
22 |
23 | if ($newline) {
24 | $this->lines[] = $this->line;
25 | $this->line = '';
26 | }
27 | }
28 |
29 | public function getContent()
30 | {
31 | if ($this->line) {
32 | $this->lines[] = $this->line;
33 | $this->line = '';
34 | }
35 |
36 | return trim(explode(PHP_EOL, $this->lines));
37 | }
38 |
39 | public function getLines()
40 | {
41 | return $this->lines;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Http/Controllers/LaADuoController.php:
--------------------------------------------------------------------------------
1 | header('Laaduo')
30 | ->body('prefixes not seted ,pleace edit config in `config/admin.php`
' .
31 | "'extensions' => [
32 | 'la-a-duo' => [
33 | // Set to `false` if you want to disable this extension
34 | 'enable' => true,
35 | // ['admin1', 'admin2', ... ]
36 | 'prefixes' => ['admin1'],
37 | ]
38 | ],
");
39 |
40 | return;
41 | }
42 |
43 | if (LaADuoExt::$bootPrefix) {
44 | return $content
45 | ->header('Laaduo')
46 | ->body("Pleace open this page in laravel-admin base `" . url(LaADuoExt::$basePrefix . '/la-a-duo') . "`.
");
47 | }
48 |
49 | $prefix = request('prefix', '');
50 |
51 | $commonds = array_filter(request('commonds', []));
52 |
53 | $lines = [];
54 |
55 | if (!empty($prefix) && !empty($commonds)) {
56 | if (in_array('install', $commonds)) {
57 | $installer = new Installer;
58 |
59 | $installer->line("php artisan laaduo:install $prefix");
60 |
61 | try {
62 | $installer->prefix($prefix);
63 | } catch (\Exception $e) {
64 | $installer->line("" . $e->getMessage() . "");
65 | }
66 |
67 | $lines = array_merge($lines, $installer->getLines());
68 | }
69 |
70 | if (in_array('route', $commonds)) {
71 | $router = new Router;
72 |
73 | $router->line("php artisan laaduo:route $prefix");
74 |
75 | try {
76 | $router->getRoutes();
77 | $router->prefix($prefix);
78 | } catch (\Exception $e) {
79 | $router->line("" . $e->getMessage() . "");
80 | }
81 |
82 | $lines = array_merge($lines, $router->getLines());
83 | }
84 |
85 | if (in_array('build', $commonds)) {
86 | $builder = new Builder;
87 |
88 | $builder->line("php artisan laaduo:build $prefix");
89 |
90 | $builder->prefix($prefix);
91 | try {} catch (\Exception $e) {
92 | $builder->line("" . $e->getMessage() . "");
93 | }
94 |
95 | $lines = array_merge($lines, $builder->getLines());
96 | }
97 |
98 | if (in_array('seed', $commonds)) {
99 | $seeder = new Seeder;
100 |
101 | $seeder->line("php artisan laaduo:seed $prefix");
102 |
103 | try {
104 | $seeder->prefix($prefix);
105 | } catch (\Exception $e) {
106 | $seeder->line("" . $e->getMessage() . "");
107 | }
108 |
109 | $lines = array_merge($lines, $seeder->getLines());
110 | }
111 | }
112 |
113 | return $content
114 | ->header(' ')
115 | ->row($this->form($prefixes, $lines));
116 | }
117 |
118 | protected function form($prefixes, $lines)
119 | {
120 | $form = new Form();
121 |
122 | $form->setWidth(2, 1);
123 |
124 | $form->html(view('la-a-duo::help'), 'Commonds');
125 |
126 | $arr = [];
127 |
128 | foreach ($prefixes as $p) {
129 | $arr[$p] = $p;
130 | }
131 |
132 | $form->radio('prefix', 'Prefix')->options($arr)->default(request('prefix', Arr::get($prefixes, 0)))->setWidth(6, 2);
133 |
134 | $form->checkbox('commonds', 'Commonds')
135 |
136 | ->options(['install' => 'install', 'route' => 'route', 'build' => 'build', 'seed' => 'seed'])
137 |
138 | ->default(request('commonds', ['install', 'route']))->setWidth(6, 2);
139 |
140 | $form->method('get');
141 |
142 | $form->disablePjax();
143 |
144 | $form->disableReset();
145 |
146 | $box = new Box('Laaduo', $form->render() . view('la-a-duo::output', ['lines' => $lines]));
147 |
148 | $box->solid();
149 |
150 | return $box;
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/src/LaADuoExt.php:
--------------------------------------------------------------------------------
1 | 'Laaduo',
19 | 'path' => 'la-a-duo',
20 | 'icon' => 'fa-object-ungroup',
21 | ];
22 |
23 | public $permission = [
24 | 'name' => 'Laaduo',
25 | 'slug' => 'admin.laaduo',
26 | 'path.*' => 'la-a-duo/*',
27 | 'path' => ['la-a-duo/index'],
28 | 'method' => null,
29 | 'method.*' => '*'
30 | ];
31 |
32 | /**
33 | * bootstrap admin prefix
34 | *
35 | * Can use it in `bootstrap.php` or `Admin::booting(function (){});` or `Admin::booted(function (){});`
36 | * @var string
37 | */
38 | public static $bootPrefix = '';
39 |
40 | public static $basePrefix = '';
41 |
42 | /**
43 | * Override admin config with current prefix
44 | *
45 | * @param [type] $prefix
46 | * @return void
47 | */
48 | public static function overrideConfig($prefix)
49 | {
50 | $config = config("{$prefix}", []);
51 |
52 | $baseConfig = config('admin');
53 |
54 | if (is_array($config)) {
55 |
56 | if (!Arr::get($config, 'bootstrap')) {
57 |
58 | $bootstrap = static::getBootstrap($prefix);
59 |
60 | Arr::set($config, 'bootstrap', $bootstrap);
61 | }
62 |
63 | if (!Arr::get($config, 'auth.controller')) {
64 |
65 | Arr::set($config, 'auth.controller', static::getDefaultAuthController($prefix));
66 | }
67 | } else {
68 |
69 | $config = static::defaultSetting($prefix);
70 | }
71 |
72 | if (!empty($config)) {
73 |
74 | $baseConfig = array_merge($baseConfig, $config);
75 |
76 | config(['admin' => $baseConfig]);
77 | }
78 |
79 | config([
80 | 'admin.route.prefix' => $prefix,
81 | 'admin.auth.guard' => $prefix,//in new version of laravel-admin
82 | ]);
83 | }
84 |
85 | /**
86 | * Get config path for current prefix
87 | *
88 | * @param [type] $prefix
89 | * @return void
90 | */
91 | public static function getConfigPath($prefix)
92 | {
93 | return config_path("{$prefix}.php");
94 | }
95 |
96 | /**
97 | * Get default setting for current prefix
98 | *
99 | * @param [type] $prefix
100 | * @return void
101 | */
102 | public static function defaultSetting($prefix)
103 | {
104 | return [
105 | 'bootstrap' => static::getBootstrap($prefix), 'auth.controller' => static::getDefaultAuthController($prefix),
106 | ];
107 | }
108 |
109 | /**
110 | * Get default bootstrap path for current prefix
111 | *
112 | * @param [type] $prefix
113 | * @return void
114 | */
115 | public static function getBootstrap($prefix)
116 | {
117 | $directory = app_path(ucfirst($prefix));
118 |
119 | $bootstrap = $directory . DIRECTORY_SEPARATOR . 'bootstrap.php';
120 |
121 | if (file_exists($bootstrap)) {
122 |
123 | return $bootstrap;
124 | }
125 |
126 | return admin_path('bootstrap.php');
127 | }
128 |
129 | /**
130 | * Get default auth Controller for current prefix
131 | *
132 | * @param [type] $prefix
133 | * @return void
134 | */
135 | public static function getDefaultAuthController($prefix)
136 | {
137 | return static::getNamespace($prefix) . '\\AuthController';
138 | }
139 |
140 | /**
141 | * Get default namespace Controller for current prefix
142 | *
143 | * @param [type] $prefix
144 | * @return void
145 | */
146 | public static function getNamespace($prefix)
147 | {
148 | return 'App\\' . ucfirst($prefix) . '\\Controllers';
149 | }
150 |
151 | public static function guard()
152 | {
153 | return Auth::guard(static::$bootPrefix); //return Admin::guard(); in new version of laravel-admin
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/src/LaADuoServiceProvider.php:
--------------------------------------------------------------------------------
1 | Middleware\Authenticate::class,
30 | 'lad.prefix' => Middleware\Prefix::class,
31 | 'lad.guards' => Middleware\AdminGuards::class,
32 | ];
33 |
34 | protected $middlewareGroups = [
35 | 'lad.admin' => [
36 | 'lad.auth',
37 | 'lad.guards',
38 | 'admin.pjax',
39 | 'admin.log',
40 | 'admin.bootstrap',
41 | 'admin.permission',
42 | ],
43 | ];
44 |
45 | /**
46 | * Register any application services.
47 | *
48 | * @return void
49 | */
50 | public function register()
51 | {
52 | $this->registerRouteMiddleware();
53 | }
54 |
55 | /**
56 | * {@inheritdoc}
57 | */
58 | public function boot(LaADuoExt $extension)
59 | {
60 | if (!LaADuoExt::boot()) {
61 | return;
62 | }
63 |
64 | if ($views = $extension->views()) {
65 | $this->loadViewsFrom($views, 'la-a-duo');
66 | }
67 |
68 | if ($this->app->runningInConsole() && $assets = $extension->assets()) {
69 | $this->publishes(
70 | [$assets => public_path('vendor/laravel-admin-ext/la-a-duo')],
71 | 'la-a-duo'
72 | );
73 | }
74 |
75 | $this->app->booted(function () {
76 | LaADuoExt::routes(__DIR__ . '/../routes/web.php');
77 | });
78 |
79 | $this->mapWebRoutes();
80 |
81 | $this->commands($this->commands);
82 |
83 | if (!$this->app->runningInConsole() && LaADuoExt::config('apart', true)) {
84 | Admin::booted(function () {
85 | if (!Auth::guard('admin')->guest() && !LaADuoExt::$bootPrefix) { //current is base admin
86 |
87 | $prefixes = LaADuoExt::config('prefixes', []);
88 |
89 | foreach ($prefixes as $prefix) {
90 |
91 | Session::remove(Auth::guard($prefix)->getName()); // delete session state of other prefixes guards.
92 | }
93 | }
94 | });
95 | }
96 | }
97 |
98 | /**
99 | * Define routes for the application.
100 | *
101 | * @return void
102 | */
103 | protected function mapWebRoutes()
104 | {
105 | $prefixes = LaADuoExt::config('prefixes', []);
106 |
107 | $route = config('admin.route', []);
108 |
109 | $authController = config('admin.auth.controller', '');
110 |
111 | $basePrefix = Arr::get($route, 'prefix', 'admin');
112 |
113 | $baseMiddleware = Arr::get($route, 'middleware', []);
114 |
115 | LaADuoExt::$basePrefix = $basePrefix;
116 |
117 | foreach ($prefixes as $prefix) {
118 |
119 | if ($prefix == $basePrefix) {
120 | continue;
121 | }
122 |
123 | $this->setGurd($prefix);
124 |
125 | if (!preg_match('/^\w+$/', $prefix)) {
126 | continue;
127 | }
128 |
129 | $directory = app_path(ucfirst($prefix));
130 |
131 | $middleware = $baseMiddleware;
132 |
133 | $thisMiddleware = config("{$prefix}.route.middleware", []);
134 |
135 | if (!empty($thisMiddleware)) {
136 |
137 | $middleware = $thisMiddleware;
138 | }
139 |
140 | $namespace = LaADuoExt::getNamespace($prefix);
141 |
142 | $middleware = array_diff($middleware, ['admin', 'web']);
143 |
144 | array_unshift($middleware, 'lad.admin');
145 |
146 | array_unshift($middleware, "lad.prefix:{$prefix}");
147 |
148 | array_unshift($middleware, 'web');
149 |
150 | config([
151 | 'admin.route' => [
152 | 'prefix' => $prefix,
153 | 'namespace' => $namespace,
154 | 'middleware' => $middleware,
155 | ],
156 | 'admin.auth.controller' => config("{$prefix}.auth.controller", LaADuoExt::getDefaultAuthController($prefix)),
157 | ]);
158 |
159 | if (!is_dir($directory)) {
160 | continue;
161 | }
162 |
163 | $routesPath = $directory . DIRECTORY_SEPARATOR . "routes.php";
164 |
165 | if (!file_exists($routesPath)) {
166 | continue;
167 | }
168 |
169 | $this->loadRoutesFrom($routesPath);
170 |
171 | $extRoutesFile = $directory . DIRECTORY_SEPARATOR . "extroutes.php";
172 |
173 | if (file_exists($extRoutesFile)) {
174 |
175 | $this->loadRoutesFrom($extRoutesFile);
176 | }
177 | }
178 |
179 | config([
180 | 'admin.route' => $route, 'admin.auth.controller' => $authController,
181 | ]);
182 | }
183 |
184 | /**
185 | * Add guard into /config/auth.php
186 | *
187 | * @param [type] $prefix
188 | * @return void
189 | */
190 | protected function setGurd($prefix)
191 | {
192 | config(['auth.guards.' . $prefix => [
193 | 'driver' => 'session',
194 | 'provider' => 'admin',
195 | ]]);
196 | }
197 |
198 | /**
199 | * Register the route middleware.
200 | *
201 | * @return void
202 | */
203 | protected function registerRouteMiddleware()
204 | {
205 | // register route middleware.
206 | foreach ($this->routeMiddleware as $key => $middleware) {
207 | app('router')->aliasMiddleware($key, $middleware);
208 | }
209 |
210 | // register middleware group.
211 | foreach ($this->middlewareGroups as $key => $middleware) {
212 | app('router')->middlewareGroup($key, $middleware);
213 | }
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/src/Middleware/AdminGuards.php:
--------------------------------------------------------------------------------
1 | guest()) {
16 | return $next($request);
17 | }
18 |
19 | $prefixes = LaADuoExt::config('prefixes', []);
20 |
21 | $prefixes = array_diff($prefixes, [LaADuoExt::$bootPrefix]);
22 |
23 | array_push($prefixes, 'admin');
24 |
25 | foreach ($prefixes as $prefix) {
26 |
27 | Session::remove(Auth::guard($prefix)->getName()); // delete session state of other guards.
28 | }
29 |
30 | return $next($request);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Middleware/Authenticate.php:
--------------------------------------------------------------------------------
1 | guest() && !$this->shouldPassThrough($request)) {
18 |
19 | return redirect()->guest($redirectTo);
20 | }
21 |
22 | if (!$guard->guest()) {
23 |
24 | Auth::guard('admin')->setUser($guard->user());// in old version of laravel-admin, this is needed .
25 | }
26 |
27 | return $next($request);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Middleware/Prefix.php:
--------------------------------------------------------------------------------
1 | 'Laravel-admin',
10 |
11 | 'logo' => 'Laravel admin',
12 |
13 | 'logo-mini' => 'La',
14 |
15 | 'route' => [
16 | 'middleware' => ['web', 'lad.admin'],
17 | ],
18 |
19 | 'auth' => [
20 | 'controller' => '#auth.controller#',
21 | ],
22 |
23 | 'database' => [
24 |
25 | 'connection' => '',
26 |
27 | 'users_table' => 'admin_users',
28 | 'users_model' => Encore\Admin\Auth\Database\Administrator::class,
29 |
30 | 'roles_table' => 'admin_roles',
31 | 'roles_model' => Encore\Admin\Auth\Database\Role::class,
32 |
33 | 'permissions_table' => 'admin_permissions',
34 | 'permissions_model' => Encore\Admin\Auth\Database\Permission::class,
35 |
36 | 'menu_table' => 'admin_menu',
37 | 'menu_model' => Encore\Admin\Auth\Database\Menu::class,
38 |
39 | 'operation_log_table' => 'admin_operation_log',
40 | 'user_permissions_table' => 'admin_user_permissions',
41 | 'role_users_table' => 'admin_role_users',
42 | 'role_permissions_table' => 'admin_role_permissions',
43 | 'role_menu_table' => 'admin_role_menu',
44 | ],
45 |
46 | /**
47 | * No need to set all one by one .
48 | *
49 | * If some configs are not seted in this file , they will use the values in /config/admin.php
50 | */
51 |
52 | /*
53 |
54 | 'upload' => [
55 | 'disk' => 'admin',
56 |
57 | 'directory' => [
58 | 'image' => 'images',
59 | 'file' => 'files',
60 | ],
61 | ],
62 |
63 | 'skin' => 'skin-blue-light',
64 |
65 | 'layout' => ['sidebar-mini', 'sidebar-collapse'],
66 |
67 | 'login_background_image' => '',
68 |
69 | 'show_version' => true,
70 |
71 | 'show_environment' => true,
72 |
73 | 'menu_bind_permission' => true,
74 |
75 | 'enable_default_breadcrumb' => true,
76 |
77 | 'minify_assets' => true,
78 |
79 | // etc ..
80 |
81 | */
82 |
83 | 'bootstrap' => '#bootstrap#'
84 |
85 | ];
86 |
--------------------------------------------------------------------------------
/stubs/extroutes.stub:
--------------------------------------------------------------------------------
1 | config('admin.route.prefix'),
13 | ], function (Router $router) {
14 |
15 | //#routers#
16 | });
--------------------------------------------------------------------------------