Fleet cart 在路线中使用中间件,但我在项目中找不到任何 $routemiddleware ...甚至在 kernel.php 中也找不到 ...我在哪里可以找到它?
Fleet cart using middlewares in routes but i can not find any $routemiddleware in project...not even in kernel.php ...where can i find it?
Fleet cart 在路线中使用中间件,但我在项目中找不到任何 $routemiddleware...甚至在 kernel.php 中也找不到...我在哪里可以找到它?
Laravel 版本:5.7
护照版本:7.5
内容管理系统:FleetCart
Kernel.php
namespace FleetCart\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\FleetCart\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\FleetCart\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\FleetCart\Http\Middleware\TrustProxies::class,
\FleetCart\Http\Middleware\RedirectToInstallerIfNotInstalled::class,
\FleetCart\Http\Middleware\RunUpdater::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\FleetCart\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\FleetCart\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];
}
\Modules\Accounts\Routes\public.php
Route::middleware('auth')->group(function () {
Route::get('account', 'AccountDashboardController@index')->name('account.dashboard.index');
Route::get('account/profile', 'AccountProfileController@edit')->name('account.profile.edit');
Route::put('account/profile', 'AccountProfileController@update')->name('account.profile.update');
Route::get('account/orders', 'AccountOrderController@index')->name('account.orders.index');
Route::get('account/orders/{id}', 'AccountOrderController@show')->name('account.orders.show');
Route::get('account/wishlist', 'AccountWishlistController@index')->name('account.wishlist.index');
Route::delete('account/wishlist/{productId}', 'AccountWishlistController@destroy')->name('account.wishlist.destroy');
Route::get('account/reviews', 'AccountReviewController@index')->name('account.reviews.index');
});
那个中间件('auth')是从哪里来的?没有任何其他内核文件,也没有任何其他中间件表示。没有什么.....!!
寻求帮助!
auth
中间件已在 Modules/Core/Providers/CoreServiceProvider.php
文件中注册。
检查registerMiddleware()
方法。
要使用 Fleetcart 验证 API,您需要创建一个 API 特定的中间件并在
下注册它
Modules/Core/Providers/CoreServiceProvider.php
您现在将拥有两个用于身份验证的中间件,一个用于应用程序身份验证,一个用于 api 身份验证
'auth' => \Modules\Core\Http\Middleware\Authenticate::class,
'api' => \Modules\Core\Http\Middleware\APIAuthenticate::class,
在您的 APIAUthenticate 中间件 class 下,执行身份验证检查。对于下面的内容,我正在检查请求 header 是否包含 Bearer 令牌,然后使用令牌检查数据库中的用户。
<?php
namespace Modules\Core\Http\Middleware;
use Closure;
use Log;
use Modules\User\Entities\User;
class APIAuthenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Illuminate\Http\Response
*/
public function handle($request, Closure $next)
{
if ($request->header('Authorization')) {
$key = explode(' ',$request->header('Authorization'));
Log::info(json_encode($key));
if(isset($key[1]) && !empty($key[1])){
Log::info('key: '. $key[1]);
$user = User::where('api_token', $key[1])->first();
Log::debug('user', array($user));
if(!empty($user)){
return $next($request);
}else{
return response()->json(['error'=>'Unauthenticated']);
}
}
}else{
return response()->json(['error'=>'Unauthenticated']);
}
return response()->json(['error'=>'Unauthenticated']);
}
}
Fleet cart 在路线中使用中间件,但我在项目中找不到任何 $routemiddleware...甚至在 kernel.php 中也找不到...我在哪里可以找到它?
Laravel 版本:5.7
护照版本:7.5
内容管理系统:FleetCart
Kernel.php
namespace FleetCart\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\FleetCart\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\FleetCart\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\FleetCart\Http\Middleware\TrustProxies::class,
\FleetCart\Http\Middleware\RedirectToInstallerIfNotInstalled::class,
\FleetCart\Http\Middleware\RunUpdater::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\FleetCart\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\FleetCart\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];
}
\Modules\Accounts\Routes\public.php
Route::middleware('auth')->group(function () {
Route::get('account', 'AccountDashboardController@index')->name('account.dashboard.index');
Route::get('account/profile', 'AccountProfileController@edit')->name('account.profile.edit');
Route::put('account/profile', 'AccountProfileController@update')->name('account.profile.update');
Route::get('account/orders', 'AccountOrderController@index')->name('account.orders.index');
Route::get('account/orders/{id}', 'AccountOrderController@show')->name('account.orders.show');
Route::get('account/wishlist', 'AccountWishlistController@index')->name('account.wishlist.index');
Route::delete('account/wishlist/{productId}', 'AccountWishlistController@destroy')->name('account.wishlist.destroy');
Route::get('account/reviews', 'AccountReviewController@index')->name('account.reviews.index');
});
那个中间件('auth')是从哪里来的?没有任何其他内核文件,也没有任何其他中间件表示。没有什么.....!!
寻求帮助!
auth
中间件已在 Modules/Core/Providers/CoreServiceProvider.php
文件中注册。
检查registerMiddleware()
方法。
要使用 Fleetcart 验证 API,您需要创建一个 API 特定的中间件并在
下注册它Modules/Core/Providers/CoreServiceProvider.php
您现在将拥有两个用于身份验证的中间件,一个用于应用程序身份验证,一个用于 api 身份验证
'auth' => \Modules\Core\Http\Middleware\Authenticate::class,
'api' => \Modules\Core\Http\Middleware\APIAuthenticate::class,
在您的 APIAUthenticate 中间件 class 下,执行身份验证检查。对于下面的内容,我正在检查请求 header 是否包含 Bearer 令牌,然后使用令牌检查数据库中的用户。
<?php
namespace Modules\Core\Http\Middleware;
use Closure;
use Log;
use Modules\User\Entities\User;
class APIAuthenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Illuminate\Http\Response
*/
public function handle($request, Closure $next)
{
if ($request->header('Authorization')) {
$key = explode(' ',$request->header('Authorization'));
Log::info(json_encode($key));
if(isset($key[1]) && !empty($key[1])){
Log::info('key: '. $key[1]);
$user = User::where('api_token', $key[1])->first();
Log::debug('user', array($user));
if(!empty($user)){
return $next($request);
}else{
return response()->json(['error'=>'Unauthenticated']);
}
}
}else{
return response()->json(['error'=>'Unauthenticated']);
}
return response()->json(['error'=>'Unauthenticated']);
}
}