diff --git a/app/Http/Middleware/ShopAuthenticate.php b/app/Http/Middleware/ShopAuthenticate.php index 43ef82fb..82eb9b3a 100644 --- a/app/Http/Middleware/ShopAuthenticate.php +++ b/app/Http/Middleware/ShopAuthenticate.php @@ -2,6 +2,8 @@ namespace App\Http\Middleware; +use Illuminate\Http\Request; +use Illuminate\Auth\AuthenticationException; use Illuminate\Auth\Middleware\Authenticate as Middleware; class ShopAuthenticate extends Middleware @@ -9,14 +11,29 @@ class ShopAuthenticate extends Middleware /** * Get the path the user should be redirected to when they are not authenticated. * - * @param \Illuminate\Http\Request $request - * @return string|null + * @param Request $request */ protected function redirectTo($request) { - if (! $request->expectsJson()) { - // 后台 + if (!$request->expectsJson()) { return shop_route('login.index'); } } + + + /** + * Handle an unauthenticated user. + * + * @param Request $request + * @param array $guards + * @return void + * + * @throws AuthenticationException + */ + protected function unauthenticated($request, array $guards) + { + throw new AuthenticationException( + trans('common.unauthenticated'), $guards, $this->redirectTo($request) + ); + } } diff --git a/resources/lang/en/common.php b/resources/lang/en/common.php index 5b755b0c..6f97d2ec 100644 --- a/resources/lang/en/common.php +++ b/resources/lang/en/common.php @@ -10,13 +10,12 @@ */ return [ - // action + 'error_required' => 'Please fill out the :name', + 'unauthenticated' => 'Please login first', 'success' => 'Success', 'created_success' => 'Created Successfully!', 'deleted_success' => 'Deleted Successfully!', 'restored_success' => 'Restore Successfully!', 'updated_success' => 'Updated Successfully!', - 'created_success' => 'Created Successfully!', 'get_success' => 'Get Successfully!', - 'error_required' => 'Please fill out the :name', ]; diff --git a/resources/lang/zh_cn/common.php b/resources/lang/zh_cn/common.php index ca540de8..9eda8f14 100644 --- a/resources/lang/zh_cn/common.php +++ b/resources/lang/zh_cn/common.php @@ -10,6 +10,13 @@ */ return [ 'error_required' => '请填写 :name', + 'unauthenticated' => '请先登录', + 'success' => '成功', + 'created_success' => '创建成功!', + 'deleted_success' => '删除成功!', + 'restored_success' => '恢复成功!', + 'updated_success' => '更新成功!', + 'get_success' => '获取成功!', ];