{"id":269,"date":"2024-12-15T10:53:57","date_gmt":"2024-12-15T02:53:57","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=269"},"modified":"2024-12-15T10:53:57","modified_gmt":"2024-12-15T02:53:57","slug":"laravel%e5%85%a8%e6%99%af%e4%bb%8b%e7%bb%8d%ef%bc%9a%e4%bb%8e%e5%9f%ba%e7%a1%80%e5%88%b0%e8%bf%9b%e9%98%b6%e7%9a%84%e5%85%a8%e9%9d%a2%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2024\/12\/15\/laravel%e5%85%a8%e6%99%af%e4%bb%8b%e7%bb%8d%ef%bc%9a%e4%bb%8e%e5%9f%ba%e7%a1%80%e5%88%b0%e8%bf%9b%e9%98%b6%e7%9a%84%e5%85%a8%e9%9d%a2%e8%a7%a3%e6%9e%90\/","title":{"rendered":"Laravel\u5168\u666f\u4ecb\u7ecd\uff1a\u4ece\u57fa\u7840\u5230\u8fdb\u9636\u7684\u5168\u9762\u89e3\u6790"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Laravel<\/strong> \u662fPHP\u5e38\u7528\u7684\u6846\u67b6\u4e4b\u4e00\uff0c\u662f\u4e00\u4e2a\u73b0\u4ee3\u5316\u3001\u529f\u80fd\u5f3a\u5927\u7684 PHP Web \u5e94\u7528\u6846\u67b6\uff0c\u5e7f\u6cdb\u7528\u4e8e\u6784\u5efa\u590d\u6742\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u9075\u5faa\u4e86 <strong>MVC\uff08Model-View-Controller\uff09<\/strong> \u67b6\u6784\u6a21\u5f0f\uff0c\u65e8\u5728\u7b80\u5316 Web \u5f00\u53d1\u7684\u5e38\u89c1\u4efb\u52a1\uff0c\u5982\u8def\u7531\u3001\u8ba4\u8bc1\u3001\u4f1a\u8bdd\u3001\u7f13\u5b58\u3001\u6570\u636e\u5e93\u64cd\u4f5c\u7b49\u3002Laravel \u7684\u76ee\u6807\u662f\u4f7f\u5f00\u53d1\u8005\u80fd\u591f\u4ee5\u4f18\u96c5\u3001\u6e05\u6670\u7684\u4ee3\u7801\u7f16\u5199\u529f\u80fd\u5f3a\u5927\u7684\u5e94\u7528\uff0c\u540c\u65f6\u63d0\u5347\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u672c\u6587\u5c06\u5168\u9762\u4ecb\u7ecd Laravel \u7684\u5404\u4e2a\u65b9\u9762\uff0c\u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff0c\u4e3a\u4f60\u63d0\u4f9b\u5b66\u4e60\u548c\u4f7f\u7528 Laravel \u7684\u5b8c\u6574\u6307\u5357\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. Laravel\u6982\u8ff0<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 \u4ec0\u4e48\u662fLaravel\uff1f<\/h3>\n\n\n\n<p>Laravel \u662f\u4e00\u4e2a\u5f00\u6e90\u7684 PHP Web \u5e94\u7528\u6846\u67b6\uff0c\u7531 <strong>Taylor Otwell<\/strong> \u5728 2011 \u5e74\u521b\u5efa\u3002Laravel \u63d0\u4f9b\u4e86\u4e00\u6574\u5957\u529f\u80fd\uff0c\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u6784\u5efa\u9ad8\u8d28\u91cf\u7684 Web \u5e94\u7528\u3002\u5b83\u7684\u8bbe\u8ba1\u54f2\u5b66\u5f3a\u8c03\u4f18\u96c5\u7684\u8bed\u6cd5\u3001\u7b80\u6d01\u7684\u4ee3\u7801\u548c\u5f3a\u5927\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<p>Laravel \u9002\u7528\u4e8e\u4ece\u7b80\u5355\u7684\u5c0f\u578b\u5e94\u7528\u5230\u590d\u6742\u7684\u5927\u578b\u4f01\u4e1a\u7ea7\u7cfb\u7edf\uff0c\u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\u3001\u7f13\u5b58\u3001\u961f\u5217\u3001\u4f1a\u8bdd\u7b49\u5e38\u89c1\u7684 Web \u5f00\u53d1\u9700\u6c42\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 Laravel\u7684\u6838\u5fc3\u7279\u70b9<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f18\u96c5\u7684\u8bed\u6cd5<\/strong>\uff1aLaravel \u63d0\u4f9b\u7b80\u6d01\u6613\u7528\u7684\u8bed\u6cd5\uff0c\u4f7f\u5f00\u53d1\u8005\u80fd\u591f\u4ee5\u66f4\u5c11\u7684\u4ee3\u7801\u5b9e\u73b0\u66f4\u591a\u529f\u80fd\u3002<\/li>\n\n\n\n<li><strong>\u6a21\u5757\u5316\u7ed3\u6784<\/strong>\uff1aLaravel \u7684\u5e94\u7528\u7ed3\u6784\u975e\u5e38\u6e05\u6670\uff0c\u4fbf\u4e8e\u6269\u5c55\u548c\u7ef4\u62a4\u3002<\/li>\n\n\n\n<li><strong>\u5185\u7f6e\u5de5\u5177\u548c\u529f\u80fd<\/strong>\uff1a\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u5185\u7f6e\u5de5\u5177\uff08\u5982\u8def\u7531\u3001\u6570\u636e\u5e93\u8fc1\u79fb\u3001\u961f\u5217\u7cfb\u7edf\u3001\u8ba4\u8bc1\u3001\u90ae\u4ef6\u7b49\uff09\u6765\u5e2e\u52a9\u5f00\u53d1\u8005\u9ad8\u6548\u5de5\u4f5c\u3002<\/li>\n\n\n\n<li><strong>\u751f\u6001\u7cfb\u7edf\u5b8c\u5584<\/strong>\uff1aLaravel \u62e5\u6709\u5f3a\u5927\u7684\u751f\u6001\u7cfb\u7edf\uff0c\u5305\u542b\u4e86\u5982 <strong>Laravel Forge<\/strong>\u3001<strong>Laravel Nova<\/strong>\u3001<strong>Laravel Envoyer<\/strong> \u7b49\u5de5\u5177\uff0c\u5e2e\u52a9\u5f00\u53d1\u3001\u90e8\u7f72\u3001\u76d1\u63a7\u548c\u7ba1\u7406\u5e94\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. Laravel\u57fa\u7840\u6982\u5ff5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 \u8def\u7531\u4e0e\u8bf7\u6c42\u5904\u7406<\/h3>\n\n\n\n<p>\u5728 Laravel \u4e2d\uff0c\u8def\u7531\u8d1f\u8d23\u5c06 HTTP \u8bf7\u6c42\u5206\u914d\u7ed9\u76f8\u5e94\u7684\u63a7\u5236\u5668\u6216\u95ed\u5305\u51fd\u6570\u8fdb\u884c\u5904\u7406\u3002\u8def\u7531\u662f Laravel \u5e94\u7528\u7684\u5165\u53e3\u70b9\uff0c\u901a\u5e38\u5b9a\u4e49\u5728 <code>routes\/web.php<\/code> \u6587\u4ef6\u4e2d\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u57fa\u672c\u8def\u7531\u5b9a\u4e49<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5339\u914d GET \u8bf7\u6c42\nRoute::get('\/', function () {\n    return view('welcome');\n});\n\n\/\/ \u5339\u914d POST \u8bf7\u6c42\nRoute::post('\/submit', function () {\n    \/\/ \u5904\u7406\u8868\u5355\u63d0\u4ea4\n});<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u8def\u7531\u4e0e\u63a7\u5236\u5668\u7684\u7ed1\u5b9a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u8def\u7531\u6307\u5411\u63a7\u5236\u5668\u65b9\u6cd5\nRoute::get('\/user\/{id}', 'UserController@show');\n\n\/\/ \u63a7\u5236\u5668\u793a\u4f8b\nclass UserController extends Controller {\n    public function show($id) {\n        return \"User ID: \" . $id;\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 \u63a7\u5236\u5668\uff08Controllers\uff09<\/h3>\n\n\n\n<p>\u63a7\u5236\u5668\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u4e2d\u67a2\uff0c\u8d1f\u8d23\u5904\u7406\u7528\u6237\u8bf7\u6c42\u3001\u8c03\u7528\u6a21\u578b\u548c\u8fd4\u56de\u54cd\u5e94\u3002\u63a7\u5236\u5668\u662f\u901a\u8fc7 Artisan \u547d\u4ee4\u751f\u6210\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan make:controller UserController<\/code><\/pre>\n\n\n\n<p>\u63a7\u5236\u5668\u901a\u5e38\u653e\u7f6e\u5728 <code>app\/Http\/Controllers<\/code> \u76ee\u5f55\u4e0b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 \u6a21\u578b\uff08Models\uff09<\/h3>\n\n\n\n<p>\u6a21\u578b\u662f\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u7684\u6838\u5fc3\uff0c\u5b83\u4f7f\u7528 <strong>Eloquent ORM<\/strong> \u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u3002\u901a\u8fc7\u6a21\u578b\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u975e\u5e38\u7b80\u6d01\u5730\u5bf9\u6570\u636e\u5e93\u8868\u8fdb\u884c\u589e\u5220\u6539\u67e5\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u57fa\u672c\u6a21\u578b<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>use Illuminate\\Database\\Eloquent\\Model;\n\nclass Post extends Model {\n    protected $fillable = &#91;'title', 'content'];\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f7f\u7528\u6a21\u578b\u8fdb\u884c\u6570\u636e\u64cd\u4f5c<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u521b\u5efa\u65b0\u8bb0\u5f55\nPost::create(&#91;'title' =&gt; 'New Post', 'content' =&gt; 'This is a new post.']);\n\n\/\/ \u67e5\u627e\u8bb0\u5f55\n$post = Post::find(1);\n\n\/\/ \u66f4\u65b0\u8bb0\u5f55\n$post-&gt;title = 'Updated Title';\n$post-&gt;save();<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.4 \u89c6\u56fe\uff08Views\uff09<\/h3>\n\n\n\n<p>Laravel \u4f7f\u7528 <strong>Blade \u6a21\u677f\u5f15\u64ce<\/strong> \u6765\u751f\u6210\u52a8\u6001 HTML \u5185\u5bb9\u3002Blade \u8bed\u6cd5\u7b80\u5355\u3001\u76f4\u89c2\uff0c\u4e14\u652f\u6301\u63a7\u5236\u7ed3\u6784\u3001\u6a21\u677f\u7ee7\u627f\u7b49\u529f\u80fd\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Blade \u8bed\u6cd5\u793a\u4f8b<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5b9a\u4e49\u53d8\u91cf\u5e76\u4f20\u9012\u5230\u89c6\u56fe\nreturn view('welcome', &#91;'name' =&gt; 'John']);\n\n\/\/ \u5728\u89c6\u56fe\u6587\u4ef6\u4e2d\n&lt;h1&gt;Hello, {{ $name }}&lt;\/h1&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.5 \u6570\u636e\u5e93\u8fc1\u79fb\uff08Migrations\uff09<\/h3>\n\n\n\n<p>Laravel \u4f7f\u7528\u6570\u636e\u5e93\u8fc1\u79fb\u6765\u7ba1\u7406\u6570\u636e\u5e93\u7684\u7ed3\u6784\uff0c\u7c7b\u4f3c\u4e8e\u7248\u672c\u63a7\u5236\u3002\u901a\u8fc7\u8fc1\u79fb\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u548c\u4fee\u6539\u6570\u636e\u5e93\u8868\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u521b\u5efa\u8fc1\u79fb\u6587\u4ef6<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan make:migration create_posts_table<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u8fc1\u79fb\u6587\u4ef6\u793a\u4f8b<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public function up()\n{\n    Schema::create('posts', function (Blueprint $table) {\n        $table-&gt;id();\n        $table-&gt;string('title');\n        $table-&gt;text('content');\n        $table-&gt;timestamps();\n    });\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u6267\u884c\u8fc1\u79fb<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan migrate<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.6 \u8868\u5355\u9a8c\u8bc1<\/h3>\n\n\n\n<p>Laravel \u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u8868\u5355\u9a8c\u8bc1\u529f\u80fd\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u65b9\u4fbf\u5730\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u9a8c\u8bc1\u8bf7\u6c42\u6570\u636e<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$request-&gt;validate(&#91;\n    'title' =&gt; 'required|max:255',\n    'content' =&gt; 'required',\n]);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. Laravel\u8fdb\u9636\u529f\u80fd<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 \u8def\u7531\u4e2d\u95f4\u4ef6<\/h3>\n\n\n\n<p>\u4e2d\u95f4\u4ef6\u53ef\u4ee5\u5728\u8bf7\u6c42\u8fdb\u5165\u5e94\u7528\u524d\u3001\u6216\u5728\u54cd\u5e94\u8fd4\u56de\u524d\u6267\u884c\u4efb\u52a1\u3002Laravel \u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u4e2d\u95f4\u4ef6\uff08\u5982\u8ba4\u8bc1\u3001CSRF \u4fdd\u62a4\u7b49\uff09\uff0c\u540c\u65f6\u4e5f\u652f\u6301\u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b9a\u4e49\u4e2d\u95f4\u4ef6<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan make:middleware CheckAge<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u4e2d\u95f4\u4ef6\u793a\u4f8b\npublic function handle($request, Closure $next)\n{\n    if (auth()-&gt;user()-&gt;age &lt; 18) {\n        return redirect('home');\n    }\n    return $next($request);\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u6ce8\u518c\u4e2d\u95f4\u4ef6<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5728 app\/Http\/Kernel.php \u4e2d\u6ce8\u518c\nprotected $routeMiddleware = &#91;\n    'check.age' =&gt; \\App\\Http\\Middleware\\CheckAge::class,\n];<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f7f\u7528\u4e2d\u95f4\u4ef6<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>Route::get('\/profile', 'ProfileController@show')-&gt;middleware('check.age');<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 \u8ba4\u8bc1\u4e0e\u6388\u6743<\/h3>\n\n\n\n<p>Laravel \u5185\u7f6e\u4e86\u5f3a\u5927\u7684\u8ba4\u8bc1\u7cfb\u7edf\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u4e3a\u5e94\u7528\u6dfb\u52a0\u7528\u6237\u6ce8\u518c\u3001\u767b\u5f55\u3001\u5bc6\u7801\u91cd\u7f6e\u7b49\u529f\u80fd\u3002\u6388\u6743\u65b9\u9762\uff0cLaravel \u63d0\u4f9b\u4e86 <strong>Policy<\/strong> \u548c <strong>Gate<\/strong> \u6765\u8fdb\u884c\u6743\u9650\u63a7\u5236\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u8ba4\u8bc1<\/h4>\n\n\n\n<p>\u901a\u8fc7 Artisan \u547d\u4ee4\u751f\u6210\u8ba4\u8bc1\u76f8\u5173\u7684\u63a7\u5236\u5668\u548c\u89c6\u56fe\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan make:auth<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u6388\u6743\uff08Policy\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan make:policy PostPolicy<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Policy \u793a\u4f8b\npublic function update(User $user, Post $post)\n{\n    return $user-&gt;id === $post-&gt;user_id;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.3 \u961f\u5217\u4e0e\u4efb\u52a1<\/h3>\n\n\n\n<p>Laravel \u7684\u961f\u5217\u7cfb\u7edf\u4f7f\u5f97\u5904\u7406\u5ef6\u8fdf\u4efb\u52a1\u53d8\u5f97\u975e\u5e38\u7b80\u5355\u3002\u4f60\u53ef\u4ee5\u5c06\u4efb\u52a1\u63a8\u9001\u5230\u961f\u5217\u4e2d\u8fdb\u884c\u5f02\u6b65\u5904\u7406\uff0c\u907f\u514d\u957f\u65f6\u95f4\u7684\u963b\u585e\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u521b\u5efa\u961f\u5217\u4efb\u52a1<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan make:job SendEmail<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5728 SendEmail \u4efb\u52a1\u7c7b\u4e2d\u5b9a\u4e49 handle \u65b9\u6cd5\npublic function handle()\n{\n    Mail::to($this-&gt;user-&gt;email)-&gt;send(new WelcomeEmail());\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u5c06\u4efb\u52a1\u63a8\u9001\u5230\u961f\u5217<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SendEmail::dispatch($user);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.4 \u4e8b\u4ef6\u4e0e\u76d1\u542c\u5668<\/h3>\n\n\n\n<p>Laravel \u63d0\u4f9b\u4e86\u4e8b\u4ef6\u548c\u76d1\u542c\u5668\u7cfb\u7edf\uff0c\u80fd\u591f\u8ba9\u4f60\u8f7b\u677e\u89e3\u8026\u5e94\u7528\u4e2d\u7684\u5404\u4e2a\u90e8\u5206\u3002\u4e8b\u4ef6\u53ef\u4ee5\u89e6\u53d1\u591a\u4e2a\u76d1\u542c\u5668\uff0c\u4ece\u800c\u5904\u7406\u591a\u79cd\u4efb\u52a1\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u521b\u5efa\u4e8b\u4ef6\u548c\u76d1\u542c\u5668<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan make:event UserRegistered\nphp artisan make:listener SendWelcomeEmail --event=UserRegistered<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.5 \u5305\u4e0e\u6269\u5c55<\/h3>\n\n\n\n<p>Laravel \u6709\u4e30\u5bcc\u7684\u7b2c\u4e09\u65b9\u5305\u751f\u6001\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5728\u5e94\u7528\u4e2d\u96c6\u6210\u5404\u79cd\u529f\u80fd\u3002\u4f8b\u5982\uff0c\u96c6\u6210\u652f\u4ed8\u63a5\u53e3\u3001API \u8bf7\u6c42\u5904\u7406\u3001\u56fe\u50cf\u5904\u7406\u7b49\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u901a\u8fc7 <strong>Composer<\/strong> \u5b89\u88c5\u5305\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer require package-name<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.6 Laravel Mix\uff08\u524d\u7aef\u6784\u5efa\u5de5\u5177\uff09<\/h3>\n\n\n\n<p>Laravel Mix \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u524d\u7aef\u6784\u5efa\u5de5\u5177\uff0c\u5b83\u57fa\u4e8e Webpack \u914d\u7f6e\uff0c\u80fd\u591f\u5e2e\u52a9\u5f00\u53d1\u8005\u5904\u7406 CSS\u3001JS \u7b49\u8d44\u6e90\u6587\u4ef6\u7684\u6253\u5305\u4e0e\u4f18\u5316\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5b89\u88c5\u4f9d\u8d56\nnpm install\n\n\/\/ \u7f16\u8bd1\u8d44\u6e90\nnpm run dev<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4. Laravel\u6700\u4f73\u5b9e\u8df5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">4.1 \u9075\u5faa MVC \u67b6\u6784<\/h3>\n\n\n\n<p>\u786e\u4fdd\u63a7\u5236\u5668\u8d1f\u8d23\u4e1a\u52a1\u903b\u8f91\uff0c\u89c6\u56fe\u8d1f\u8d23\u5c55\u793a\uff0c\u6a21\u578b\u8d1f\u8d23\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u3002\u4fdd\u6301\u4ee3\u7801\u7684\u6e05\u6670\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.2 \u4ee3\u7801\u590d\u7528<\/h3>\n\n\n\n<p>\u5229\u7528 Laravel \u63d0\u4f9b\u7684 <strong>Service Providers<\/strong>\u3001<strong>Helper \u51fd\u6570<\/strong> \u548c <strong>Facades<\/strong>\uff0c\u5c06\u91cd\u590d\u4ee3\u7801\u63d0\u53d6\u5230\u9002\u5f53\u7684\u4f4d\u7f6e\uff0c\u4fdd\u6301\u4ee3\u7801\u7b80\u6d01\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.3 \u4f7f\u7528 Eloquent ORM<\/h3>\n\n\n\n<p>\u5c3d\u53ef\u80fd\u4f7f\u7528 Eloquent ORM \u6765\u64cd\u4f5c\u6570\u636e\u5e93\uff0c\u8fd9\u6837\u53ef\u4ee5\u8ba9\u4f60\u7684\u4ee3\u7801\u66f4\u7b80\u6d01\u3001\u53ef\u8bfb\u3002\u907f\u514d\u624b\u5199 SQL \u67e5\u8be2\uff0c\u5229\u7528 Eloquent \u63d0\u4f9b\u7684\u67e5\u8be2\u6784\u5efa\u5668\u6765\u5904\u7406\u590d\u6742\u7684\u6570\u636e\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.4 \u8fdb\u884c\u81ea\u52a8\u5316\u6d4b\u8bd5<\/h3>\n\n\n\n<p>Laravel \u652f\u6301 PHPUnit \u548c Laravel Dusk \u7b49\u6d4b\u8bd5\u5de5\u5177\u3002\u901a\u8fc7\u7f16\u5199\u81ea\u52a8\u5316\u6d4b\u8bd5\u6765\u4fdd\u8bc1\u5e94\u7528\u7684\u7a33\u5b9a\u6027\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan make:test PostTest<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u603b\u7ed3<\/h2>\n\n\n\n<p>Laravel \u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u3001\u7075\u6d3b\u4e14\u6613\u4e8e\u4f7f\u7528\u7684 PHP \u6846\u67b6\uff0c\u5b83\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u4ece\u57fa\u7840\u5230\u8fdb\u9636\u7684\u5404\u79cd\u5de5\u5177\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u6784\u5efa\u9ad8\u8d28\u91cf\u3001\u53ef\u7ef4\u62a4\u7684 Web \u5e94\u7528\u3002\u901a\u8fc7\u7b80\u6d01\u7684\u8bed\u6cd5\u3001\u5f3a\u5927\u7684\u529f\u80fd\u4ee5\u53ca\u6d3b\u8dc3\u7684\u793e\u533a\uff0cLaravel \u5df2\u6210\u4e3a PHP \u5f00\u53d1\u8005\u7684\u9996\u9009\u6846\u67b6\u4e4b\u4e00\u3002\u65e0\u8bba\u662f\u5f00\u53d1\u5c0f\u578b\u535a\u5ba2\u8fd8\u662f\u5927\u578b\u4f01\u4e1a\u7ea7\u5e94\u7528\uff0cLaravel \u90fd\u80fd\u6ee1\u8db3\u5404\u79cd\u9700\u6c42\uff0c\u63d0\u5347\u5f00\u53d1\u6548\u7387\u5e76\u786e\u4fdd\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n\n\n\n<p>\u66f4\u591a\u4fe1\u606f\u8bf7\u5173\u6ce8\u5176\u4ed6\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel \u662fPHP\u5e38\u7528\u7684\u6846\u67b6\u4e4b\u4e00\uff0c\u662f\u4e00\u4e2a\u73b0\u4ee3\u5316\u3001\u529f\u80fd\u5f3a\u5927\u7684 PHP Web \u5e94\u7528\u6846\u67b6\uff0c\u5e7f\u6cdb\u7528\u4e8e\u6784\u5efa\u590d\u6742\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[],"class_list":["post-269","post","type-post","status-publish","format-standard","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=269"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/269\/revisions"}],"predecessor-version":[{"id":270,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/269\/revisions\/270"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}