支持插件自定义后台路由
This commit is contained in:
parent
1f4c3914dd
commit
045fb2fcf5
|
|
@ -34,9 +34,12 @@ class ShareViewData
|
|||
|
||||
if (is_admin()) {
|
||||
$adminLanguages = $this->handleAdminLanguages();
|
||||
$currentLanguage = current_user()->locale ?: 'en';
|
||||
View::share('admin_languages', $adminLanguages);
|
||||
View::share('admin_language', collect($adminLanguages)->where('code', $currentLanguage)->first());
|
||||
$loggedAdminUser = current_user();
|
||||
if ($loggedAdminUser) {
|
||||
$currentLanguage = $loggedAdminUser->locale ?: 'en';
|
||||
View::share('admin_languages', $adminLanguages);
|
||||
View::share('admin_language', collect($adminLanguages)->where('code', $currentLanguage)->first());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
namespace Beike\Shop\Providers;
|
||||
|
||||
use Beike\Plugin\Manager;
|
||||
use Beike\Models\AdminUser;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
|
|
@ -77,12 +78,23 @@ class PluginServiceProvider extends ServiceProvider
|
|||
private function loadRoutes($pluginCode)
|
||||
{
|
||||
$pluginBasePath = $this->pluginBasePath;
|
||||
$routePath = "{$pluginBasePath}/{$pluginCode}/routes.php";
|
||||
if (file_exists($routePath)) {
|
||||
$shopRoutePath = "{$pluginBasePath}/{$pluginCode}/Routes/shop.php";
|
||||
if (file_exists($shopRoutePath)) {
|
||||
Route::prefix('plugin')
|
||||
->middleware('web')
|
||||
->group(function () use ($routePath) {
|
||||
$this->loadRoutesFrom($routePath);
|
||||
->middleware('shop')
|
||||
->group(function () use ($shopRoutePath) {
|
||||
$this->loadRoutesFrom($shopRoutePath);
|
||||
});
|
||||
}
|
||||
|
||||
$adminRoutePath = "{$pluginBasePath}/{$pluginCode}/Routes/admin.php";
|
||||
if (file_exists($adminRoutePath)) {
|
||||
$adminName = admin_name();
|
||||
Route::prefix($adminName)
|
||||
->name('admin.')
|
||||
->middleware(['admin', 'admin_auth:' . AdminUser::AUTH_GUARD])
|
||||
->group(function () use ($adminRoutePath) {
|
||||
$this->loadRoutesFrom($adminRoutePath);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,17 @@
|
|||
namespace Plugin\HeaderMenu\Controllers;
|
||||
|
||||
use Beike\Repositories\ProductRepo;
|
||||
use Beike\Shop\Http\Controllers\Controller;
|
||||
use Beike\Shop\Http\Resources\ProductList;
|
||||
use Beike\Shop\Http\Controllers\Controller;
|
||||
|
||||
class MenusController extends Controller
|
||||
{
|
||||
public function getRoutes(): string
|
||||
{
|
||||
return __METHOD__;
|
||||
}
|
||||
|
||||
|
||||
public function latestProducts()
|
||||
{
|
||||
$products = ProductRepo::getBuilder()->orderByDesc('updated_at')->paginate(40);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* admin.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @created 2022-08-04 16:17:53
|
||||
* @modified 2022-08-04 16:17:53
|
||||
*/
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Plugin\HeaderMenu\Controllers\MenusController;
|
||||
|
||||
Route::get('/routes', [MenusController::class, 'getRoutes'])->name('routes');
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* shop.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @created 2022-08-04 16:17:44
|
||||
* @modified 2022-08-04 16:17:44
|
||||
*/
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Plugin\HeaderMenu\Controllers\MenusController;
|
||||
|
||||
Route::get('/latest_products', [MenusController::class, 'latestProducts'])->name('plugin.latest_products');
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* route.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @created 2022-07-21 09:35:05
|
||||
* @modified 2022-07-21 09:35:05
|
||||
*/
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/latest_products', '\Plugin\HeaderMenu\Controllers\MenusController@latestProducts')->name('plugin.latest_products');
|
||||
Loading…
Reference in New Issue