李帅

init

...@@ -3,10 +3,13 @@ ...@@ -3,10 +3,13 @@
3 namespace App\Exceptions; 3 namespace App\Exceptions;
4 4
5 use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; 5 use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
6 +use Jiannei\Response\Laravel\Support\Traits\ExceptionTrait;
6 use Throwable; 7 use Throwable;
7 8
8 class Handler extends ExceptionHandler 9 class Handler extends ExceptionHandler
9 { 10 {
11 + use ExceptionTrait;
12 +
10 /** 13 /**
11 * A list of the exception types that are not reported. 14 * A list of the exception types that are not reported.
12 * 15 *
......
...@@ -40,8 +40,8 @@ class Kernel extends HttpKernel ...@@ -40,8 +40,8 @@ class Kernel extends HttpKernel
40 ], 40 ],
41 41
42 'api' => [ 42 'api' => [
43 - // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, 43 + \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
44 - 'throttle:api', 44 +// 'throttle:api',
45 \Illuminate\Routing\Middleware\SubstituteBindings::class, 45 \Illuminate\Routing\Middleware\SubstituteBindings::class,
46 ], 46 ],
47 ]; 47 ];
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
9 "dcat/laravel-admin": "2.*", 9 "dcat/laravel-admin": "2.*",
10 "fruitcake/laravel-cors": "^2.0", 10 "fruitcake/laravel-cors": "^2.0",
11 "guzzlehttp/guzzle": "^7.0.1", 11 "guzzlehttp/guzzle": "^7.0.1",
12 + "jiannei/laravel-enum": "^3.0",
13 + "jiannei/laravel-response": "^4.0",
12 "laravel/framework": "^8.75", 14 "laravel/framework": "^8.75",
13 "laravel/sanctum": "^2.11", 15 "laravel/sanctum": "^2.11",
14 "laravel/socialite": "^5.2", 16 "laravel/socialite": "^5.2",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
4 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 4 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 "This file is @generated automatically" 5 "This file is @generated automatically"
6 ], 6 ],
7 - "content-hash": "049d4f5ac63a95630253c84eb084183e", 7 + "content-hash": "298c2071717850e70431d14a67202770",
8 "packages": [ 8 "packages": [
9 { 9 {
10 "name": "asm89/stack-cors", 10 "name": "asm89/stack-cors",
...@@ -1557,6 +1557,171 @@ ...@@ -1557,6 +1557,171 @@
1557 "time": "2021-10-06T17:43:30+00:00" 1557 "time": "2021-10-06T17:43:30+00:00"
1558 }, 1558 },
1559 { 1559 {
1560 + "name": "jiannei/helpers",
1561 + "version": "v0.2.1",
1562 + "source": {
1563 + "type": "git",
1564 + "url": "https://github.com/Jiannei/helpers.git",
1565 + "reference": "1fa669201e3c4f9b384ffdb5ab3ea4caabc594f3"
1566 + },
1567 + "dist": {
1568 + "type": "zip",
1569 + "url": "https://api.github.com/repos/Jiannei/helpers/zipball/1fa669201e3c4f9b384ffdb5ab3ea4caabc594f3",
1570 + "reference": "1fa669201e3c4f9b384ffdb5ab3ea4caabc594f3",
1571 + "shasum": "",
1572 + "mirrors": [
1573 + {
1574 + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
1575 + "preferred": true
1576 + }
1577 + ]
1578 + },
1579 + "type": "library",
1580 + "autoload": {
1581 + "files": [
1582 + "src/helpers.php"
1583 + ]
1584 + },
1585 + "notification-url": "https://packagist.org/downloads/",
1586 + "license": [
1587 + "MIT"
1588 + ],
1589 + "authors": [
1590 + {
1591 + "name": "jiannei",
1592 + "email": "longjian.huang@foxmail.com"
1593 + }
1594 + ],
1595 + "description": "Some helper functions.",
1596 + "support": {
1597 + "issues": "https://github.com/Jiannei/helpers/issues",
1598 + "source": "https://github.com/Jiannei/helpers/tree/v0.2.1"
1599 + },
1600 + "time": "2021-06-16T03:01:10+00:00"
1601 + },
1602 + {
1603 + "name": "jiannei/laravel-enum",
1604 + "version": "v3.0.0",
1605 + "source": {
1606 + "type": "git",
1607 + "url": "https://github.com/Jiannei/laravel-enum.git",
1608 + "reference": "a3686fda3cf6c51942d13a50bdcd5f41622907b2"
1609 + },
1610 + "dist": {
1611 + "type": "zip",
1612 + "url": "https://api.github.com/repos/Jiannei/laravel-enum/zipball/a3686fda3cf6c51942d13a50bdcd5f41622907b2",
1613 + "reference": "a3686fda3cf6c51942d13a50bdcd5f41622907b2",
1614 + "shasum": "",
1615 + "mirrors": [
1616 + {
1617 + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
1618 + "preferred": true
1619 + }
1620 + ]
1621 + },
1622 + "require": {
1623 + "ext-json": "*",
1624 + "jiannei/helpers": "^0.2.1"
1625 + },
1626 + "require-dev": {
1627 + "orchestra/testbench": "^6.0",
1628 + "phpunit/phpunit": "^9.3.3"
1629 + },
1630 + "type": "library",
1631 + "extra": {
1632 + "laravel": {
1633 + "providers": [
1634 + "Jiannei\\Enum\\Laravel\\Providers\\LaravelServiceProvider"
1635 + ]
1636 + }
1637 + },
1638 + "autoload": {
1639 + "psr-4": {
1640 + "Jiannei\\Enum\\Laravel\\": "src"
1641 + }
1642 + },
1643 + "notification-url": "https://packagist.org/downloads/",
1644 + "license": [
1645 + "MIT"
1646 + ],
1647 + "authors": [
1648 + {
1649 + "name": "jiannei",
1650 + "email": "longjian.huang@foxmail.com"
1651 + }
1652 + ],
1653 + "description": "A simple and easy-to-use enumeration extension package to help you manage enumerations in your project more conveniently, supporting Laravel and Lumen",
1654 + "support": {
1655 + "issues": "https://github.com/Jiannei/laravel-enum/issues",
1656 + "source": "https://github.com/Jiannei/laravel-enum/tree/v3.0.0"
1657 + },
1658 + "time": "2021-09-19T14:27:22+00:00"
1659 + },
1660 + {
1661 + "name": "jiannei/laravel-response",
1662 + "version": "v4.1.0",
1663 + "source": {
1664 + "type": "git",
1665 + "url": "https://github.com/Jiannei/laravel-response.git",
1666 + "reference": "5193800903dd677a02bb43b586bbdf2f6f342eea"
1667 + },
1668 + "dist": {
1669 + "type": "zip",
1670 + "url": "https://api.github.com/repos/Jiannei/laravel-response/zipball/5193800903dd677a02bb43b586bbdf2f6f342eea",
1671 + "reference": "5193800903dd677a02bb43b586bbdf2f6f342eea",
1672 + "shasum": "",
1673 + "mirrors": [
1674 + {
1675 + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
1676 + "preferred": true
1677 + }
1678 + ]
1679 + },
1680 + "require": {
1681 + "php": "^7.2.5|^8.0"
1682 + },
1683 + "require-dev": {
1684 + "jiannei/laravel-enum": "^3.0",
1685 + "laravel/legacy-factories": "^1.1",
1686 + "league/fractal": "^0.19.2",
1687 + "orchestra/database": "^6.0",
1688 + "orchestra/testbench": "^6.0",
1689 + "phpunit/phpunit": "^9.3.3"
1690 + },
1691 + "type": "library",
1692 + "extra": {
1693 + "laravel": {
1694 + "providers": [
1695 + "Jiannei\\Response\\Laravel\\Providers\\LaravelServiceProvider"
1696 + ],
1697 + "aliases": {
1698 + "Response": "Jiannei\\Response\\Laravel\\Support\\Facades\\Response"
1699 + }
1700 + }
1701 + },
1702 + "autoload": {
1703 + "psr-4": {
1704 + "Jiannei\\Response\\Laravel\\": "src"
1705 + }
1706 + },
1707 + "notification-url": "https://packagist.org/downloads/",
1708 + "license": [
1709 + "MIT"
1710 + ],
1711 + "authors": [
1712 + {
1713 + "name": "jiannei",
1714 + "email": "longjian.huang@foxmail.com"
1715 + }
1716 + ],
1717 + "description": "Laravel api response data format.",
1718 + "support": {
1719 + "issues": "https://github.com/Jiannei/laravel-response/issues",
1720 + "source": "https://github.com/Jiannei/laravel-response/tree/v4.1.0"
1721 + },
1722 + "time": "2021-12-24T08:17:43+00:00"
1723 + },
1724 + {
1560 "name": "laravel/framework", 1725 "name": "laravel/framework",
1561 "version": "v8.77.1", 1726 "version": "v8.77.1",
1562 "source": { 1727 "source": {
......
...@@ -40,6 +40,10 @@ return [ ...@@ -40,6 +40,10 @@ return [
40 'driver' => 'session', 40 'driver' => 'session',
41 'provider' => 'users', 41 'provider' => 'users',
42 ], 42 ],
43 + 'api' => [
44 + 'driver' => 'token',
45 + 'provider' => 'one_users',
46 + ]
43 ], 47 ],
44 48
45 /* 49 /*
...@@ -69,6 +73,10 @@ return [ ...@@ -69,6 +73,10 @@ return [
69 // 'driver' => 'database', 73 // 'driver' => 'database',
70 // 'table' => 'users', 74 // 'table' => 'users',
71 // ], 75 // ],
76 + 'one_users' => [
77 + 'driver' => 'eloquent',
78 + 'model' => App\Models\OneUser::class,
79 + ]
72 ], 80 ],
73 81
74 /* 82 /*
......
1 +<?php
2 +
3 +/*
4 + * This file is part of the Jiannei/laravel-enum.
5 + *
6 + * (c) Jiannei <longjian.huang@foxmail.com>
7 + *
8 + * This source file is subject to the MIT license that is bundled
9 + * with this source code in the file LICENSE.
10 + */
11 +
12 +return [
13 + 'localization' => [
14 + 'key' => env('ENUM_LOCALIZATION_KEY', 'enums'),
15 + ],
16 +
17 + // 你可以将请求参数中用到的枚举定义在下面,通过中间件,将会被自动转换成枚举类
18 + 'transformations' => [
19 + // 参数名 => 对应的枚举类
20 +
21 + ],
22 +];
1 +<?php
2 +
3 +/*
4 + * This file is part of the Jiannei/laravel-response.
5 + *
6 + * (c) Jiannei <longjian.huang@foxmail.com>
7 + *
8 + * This source file is subject to the MIT license that is bundled
9 + * with this source code in the file LICENSE.
10 + */
11 +
12 +return [
13 + /*
14 + |--------------------------------------------------------------------------
15 + | Set the http status code when the response fails
16 + |--------------------------------------------------------------------------
17 + |
18 + | the reference options are false, 200, 500
19 + |
20 + | false, stricter http status codes such as 404, 401, 403, 500, etc. will be returned
21 + | 200, All failed responses will also return a 200 status code
22 + | 500, All failed responses return a 500 status code
23 + */
24 +
25 + 'error_code' => false,
26 +
27 + // You can use enumerations to define the code when the response is returned,
28 + // and set the response message according to the locale
29 + //
30 + // The following two enumeration packages are good choices
31 + //
32 + // https://github.com/Jiannei/laravel-enum
33 + // https://github.com/BenSampo/laravel-enum
34 +
35 + // 'enum' => '', // \Jiannei\Enum\Laravel\Repositories\Enums\HttpStatusCodeEnum::class
36 +
37 + 'enum' => \Jiannei\Enum\Laravel\Repositories\Enums\HttpStatusCodeEnum::class, //
38 +
39 + // You can set some attributes (eg:code/message/header/options) for the exception, and it will override the default attributes of the exception
40 + 'exception' => [
41 + \Illuminate\Validation\ValidationException::class => [
42 + 'code' => 422,
43 + ],
44 + \Illuminate\Auth\AuthenticationException::class => [
45 + 'message' => '用户未登录'
46 + ],
47 + \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class =>[
48 + 'message' => '',
49 + ],
50 + \Illuminate\Database\Eloquent\ModelNotFoundException::class => [
51 + 'message' => '',
52 + ],
53 + ],
54 +
55 + // Set the structure of the response data
56 + 'format' => [
57 + 'fields' => [
58 + 'status' => ['alias' => 'status', 'show' => true],
59 + 'code' => ['alias' => 'code', 'show' => true],
60 + 'message' => ['alias' => 'message', 'show' => true],
61 + 'error' => ['alias' => 'error', 'show' => true],
62 + 'data' => [
63 + 'alias' => 'data',
64 + 'show' => true,
65 +
66 + 'fields' => [
67 + // When data is nested with data, such as returning paged data, you can also set an alias for the inner data
68 + 'data' => ['alias' => 'data', 'show' => true], // data/rows/list
69 +
70 + 'meta' => [
71 + 'alia' => 'meta',
72 + 'show' => true,
73 +
74 + 'fields' => [
75 + 'pagination' => [
76 + 'alias' => 'pagination',
77 + 'show' => true,
78 +
79 + 'fields' => [
80 + 'total' => ['alias' => 'total', 'show' => true],
81 + 'count' => ['alias' => 'count', 'show' => true],
82 + 'per_page' => ['alias' => 'per_page', 'show' => true],
83 + 'current_page' => ['alias' => 'current_page', 'show' => true],
84 + 'total_pages' => ['alias' => 'total_pages', 'show' => true],
85 + 'links' => [
86 + 'alias' => 'links',
87 + 'show' => true,
88 +
89 + 'fields' => [
90 + 'previous' => ['alias' => 'previous', 'show' => true],
91 + 'next' => ['alias' => 'next', 'show' => true],
92 + ],
93 + ],
94 + ],
95 + ],
96 + ],
97 + ],
98 + ],
99 + ],
100 + ],
101 + ],
102 +];
...@@ -31,7 +31,7 @@ return [ ...@@ -31,7 +31,7 @@ return [
31 | 31 |
32 */ 32 */
33 33
34 - 'guard' => ['web'], 34 + 'guard' => ['web','api'],
35 35
36 /* 36 /*
37 |-------------------------------------------------------------------------- 37 |--------------------------------------------------------------------------
......
...@@ -14,6 +14,8 @@ use Illuminate\Support\Facades\Route; ...@@ -14,6 +14,8 @@ use Illuminate\Support\Facades\Route;
14 | 14 |
15 */ 15 */
16 16
17 -Route::middleware('auth:sanctum')->get('/user', function (Request $request) { 17 +//Route::prefix('v1')->middleware('auth:sanctum')->group(function ($api){
18 - return $request->user(); 18 +
19 -}); 19 +Route::prefix('v1')->group(function ($api){
20 +
21 +});
...\ No newline at end of file ...\ No newline at end of file
......