{"id":141,"date":"2025-04-27T09:43:18","date_gmt":"2025-04-27T01:43:18","guid":{"rendered":"https:\/\/note.yuncrown.com\/?p=141"},"modified":"2025-04-27T21:39:09","modified_gmt":"2025-04-27T13:39:09","slug":"laravel8%e4%bd%bf%e7%94%a8authsanctum%e9%aa%8c%e8%af%81api","status":"publish","type":"post","link":"https:\/\/note.yuncrown.com\/index.php\/2025\/04\/27\/laravel8%e4%bd%bf%e7%94%a8authsanctum%e9%aa%8c%e8%af%81api\/","title":{"rendered":"laravel8\u4f7f\u7528auth:sanctum\u9a8c\u8bc1api"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">\u540e\u7aef\u6b65\u9aa4<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u4fee\u6539\u8868\u540d\uff08personal_access_tokens -&gt;tbl_token \uff09\npublic function up()\n    {\n        Schema::create('tbl_token', function (Blueprint $table) {\n            $table-&gt;id();\n            $table-&gt;morphs('tokenable');\n            $table-&gt;string('name');\n            $table-&gt;string('token', 64)-&gt;unique();\n            $table-&gt;text('abilities')-&gt;nullable();\n            $table-&gt;timestamp('last_used_at')-&gt;nullable();\n            $table-&gt;timestamps();\n        });\n    }\n\/\/ \u521b\u5efatoken\u6570\u636e\u5e93\u8868\nphp artisan migrate --path=\/database\/migrations\/2019_12_14_000001_create_personal_access_tokens_table.php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fdd\u5b58token\u7684\u8868\uff08tbl_token\uff09\u8bbe\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5fc5\u987b\u7ee7\u627fSanctumPersonalAccessToken\n\/\/$timestamps\u8bbe\u7f6e\u6210true\nnamespace App\\Models;\n\nuse Laravel\\Sanctum\\PersonalAccessToken as SanctumPersonalAccessToken;\n\nclass Token extends SanctumPersonalAccessToken\n{\n    \/**\n     * \u4e0e\u6a21\u578b\u5173\u8054\u7684\u6570\u636e\u8868\n     *\n     * @var string\n     *\/\n    protected $table = 'tbl_token';\n\n    protected $guarded = &#91;];\n\n    public $timestamps = true;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u524d\u7aef\u6216\u8005api\u8c03\u7528\u5de5\u5177\u4f7f\u7528\u7684token\u662f\u767b\u5f55\u63a5\u53e3\u8fd4\u56de\u7684token\uff0c\u4e0d\u662f\u6570\u636e\u5e93\u91cc\u8bb0\u5f55\u7684\uff0c\u6570\u636e\u5e93\u91cc\u8bb0\u5f55\u7684token\u662fhash\u8fc7\u4e86\uff0c\u4e0d\u80fd\u76f4\u63a5\u7528\uff01\uff01\uff01<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u540e\u7aef\u6b65\u9aa4 \u4fdd\u5b58token\u7684\u8868\uff08tbl_token\uff09\u8bbe\u7f6e \u524d\u7aef\u6216\u8005api\u8c03\u7528\u5de5\u5177\u4f7f\u7528\u7684token\u662f\u767b\u5f55\u63a5\u53e3\u8fd4\u56de\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":5,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts\/141\/revisions"}],"predecessor-version":[{"id":148,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts\/141\/revisions\/148"}],"wp:attachment":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/media?parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/categories?post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/tags?post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}