{"id":762,"date":"2025-06-11T23:05:02","date_gmt":"2025-06-11T15:05:02","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/laravel\/762.html"},"modified":"2025-06-11T23:05:02","modified_gmt":"2025-06-11T15:05:02","slug":"laravel%ef%bc%9a%e5%9c%a8-blade-%e6%a8%a1%e6%9d%bf%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%85%a8%e5%b1%80%e5%8f%98%e9%87%8f%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/762.html","title":{"rendered":"Laravel\uff1a\u5728 Blade \u6a21\u677f\u4e2d\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u7684\u65b9\u6cd5"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">Bug&#32534;&#35793;&#29422;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; Laravel &#20013;&#65292;&#20320;&#21487;&#20197;&#36890;&#36807;&#22810;&#31181;&#26041;&#24335;&#22312; Blade &#27169;&#26495;&#20013;&#20351;&#29992;&#20840;&#23616;&#21464;&#37327;&#12290;&#20197;&#19979;&#26159;&#19968;&#20123;&#24120;&#35265;&#30340;&#26041;&#27861;&#65306;<\/p>\n<h3>1. &#20351;&#29992; <code>View::share<\/code> &#26041;&#27861;<\/h3>\n<p><code>View::share<\/code> &#26041;&#27861;&#21487;&#20197;&#23558;&#21464;&#37327;&#20849;&#20139;&#21040;&#25152;&#26377; Blade &#27169;&#26495;&#20013;&#12290;<\/p>\n<pre><code class=\"language-php\">\/\/ &#22312;&#25511;&#21046;&#22120;&#20013;\nuse IlluminateSupportFacadesView;\n\npublic function index()\n{\n    $globalVar = 'Hello, World!';\n    View::share('globalVar', $globalVar);\n\n    return view('welcome');\n}<\/code><\/pre>\n<p>&#28982;&#21518;&#22312;&#27169;&#26495;&#20013;&#20351;&#29992;&#36825;&#20010;&#21464;&#37327;&#65306;<\/p>\n<pre><code class=\"language-blade\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n    &lt;title&gt;Welcome&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;h1&gt;{{ $globalVar }}&lt;\/h1&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h3>2. &#20351;&#29992; <code>view()-&gt;share<\/code> &#26041;&#27861;<\/h3>\n<p><code>view()<\/code> &#26041;&#27861;&#20063;&#21487;&#20197;&#29992;&#26469;&#20849;&#20139;&#21464;&#37327;&#12290;<\/p>\n<pre><code class=\"language-php\">\/\/ &#22312;&#25511;&#21046;&#22120;&#20013;\nuse IlluminateSupportFacadesView;\n\npublic function index()\n{\n    $globalVar = 'Hello, World!';\n    view()-&gt;share('globalVar', $globalVar);\n\n    return view('welcome');\n}<\/code><\/pre>\n<p>&#28982;&#21518;&#22312;&#27169;&#26495;&#20013;&#20351;&#29992;&#36825;&#20010;&#21464;&#37327;&#65306;<\/p>\n<pre><code class=\"language-blade\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n    &lt;title&gt;Welcome&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;h1&gt;{{ $globalVar }}&lt;\/h1&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h3>3. &#20351;&#29992; <code>App::setShared<\/code> &#26041;&#27861;<\/h3>\n<p>&#22914;&#26524;&#20320;&#24076;&#26395;&#20840;&#23616;&#21464;&#37327;&#21482;&#22312;&#24403;&#21069;&#35831;&#27714;&#20013;&#21487;&#29992;&#65292;&#21487;&#20197;&#20351;&#29992; <code>App::setShared<\/code> &#26041;&#27861;&#12290;<\/p>\n<pre><code class=\"language-php\">\/\/ &#22312;&#25511;&#21046;&#22120;&#20013;\nuse IlluminateSupportFacadesApp;\n\npublic function index()\n{\n    $globalVar = 'Hello, World!';\n    App::setShared('globalVar', $globalVar);\n\n    return view('welcome');\n}<\/code><\/pre>\n<p>&#28982;&#21518;&#22312;&#27169;&#26495;&#20013;&#20351;&#29992;&#36825;&#20010;&#21464;&#37327;&#65306;<\/p>\n<pre><code class=\"language-blade\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n    &lt;title&gt;Welcome&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;h1&gt;{{ $globalVar }}&lt;\/h1&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h3>&#31034;&#20363;&#20195;&#30721;<\/h3>\n<p>&#20197;&#19979;&#26159;&#19968;&#20010;&#23436;&#25972;&#30340;&#31034;&#20363;&#65292;&#23637;&#31034;&#20102;&#22914;&#20309;&#22312;&#25511;&#21046;&#22120;&#20013;&#35774;&#32622;&#21644;&#22312;&#27169;&#26495;&#20013;&#20351;&#29992;&#20840;&#23616;&#21464;&#37327;&#65306;<\/p>\n<pre><code class=\"language-php\">\/\/ routes\/web.php\nRoute::get('\/hello', function () {\n    $globalVar = 'Hello, World!';\n    App::setShared('globalVar', $globalVar);\n\n    return view('welcome');\n});<\/code><\/pre>\n<pre><code class=\"language-blade\">&lt;!-- resources\/views\/welcome.blade.php --&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n    &lt;title&gt;Welcome&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;h1&gt;{{ $globalVar }}&lt;\/h1&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p>&#36890;&#36807;&#36825;&#20123;&#26041;&#27861;&#65292;&#20320;&#21487;&#20197;&#22312; Laravel &#20013;&#36731;&#26494;&#22320;&#22312; Blade &#27169;&#26495;&#20013;&#20351;&#29992;&#20840;&#23616;&#21464;&#37327;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;Bug&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#40657;&#26495;Bug&#35762;&#24072;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><h2>&#20171;&#32461;<\/h2><p>Laravel &#26159;&#19968;&#20010;&#24378;&#22823;&#30340; PHP &#26694;&#26550;&#65292;&#22240;&#20854;&#20248;&#38597;&#30340;&#35821;&#27861;&#21644;&#26377;&#29992;&#30340;&#21151;&#33021;&#32780;&#24191;&#21463;&#27426;&#36814;&#12290;Blade &#26159; Laravel &#30340;&#27169;&#26495;&#24341;&#25806;&#65292;&#20855;&#26377;&#30452;&#35266;&#19988;&#28789;&#27963;&#30340;&#29305;&#28857;&#12290;&#22312;&#19982; Blade &#27169;&#26495;&#24037;&#20316;&#26102;&#65292;&#23450;&#20041;&#21644;&#20351;&#29992;&#20840;&#23616;&#21464;&#37327;&#26159;&#19968;&#39033;&#24120;&#35265;&#30340;&#38656;&#27714;&#12290;&#22312;&#36825;&#31687;&#25945;&#31243;&#20013;&#65292;&#25105;&#20204;&#23558;&#25506;&#35752;&#22312;&#24744;&#30340; Laravel &#24212;&#29992;&#31243;&#24207;&#20013;&#36328; Blade &#35270;&#22270;&#23450;&#20041;&#21644;&#20351;&#29992;&#30340;&#21508;&#31181;&#26041;&#27861;&#12290;<\/p><h3>Global variables are those which are declared without the &#8220;static&#8221; keyword and can be accessed by any function in a program. They exist throughout the entire scope of the program, meaning they persist even after all functions have finished executing.<\/h3><p>&#22312;Laravel&#21644;Blade&#27169;&#26495;&#19978;&#19979;&#25991;&#20013;&#65292;&#20840;&#23616;&#21464;&#37327;&#26159;&#25351;&#21487;&#20197;&#22312;&#25152;&#26377;&#35270;&#22270;&#20043;&#38388;&#35775;&#38382;&#30340;&#21464;&#37327;&#65292;&#32780;&#26080;&#38656;&#27599;&#27425;&#36820;&#22238;&#25511;&#21046;&#22120;&#20013;&#30340;&#35270;&#22270;&#26102;&#37117;&#26174;&#24335;&#22320;&#20256;&#36882;&#23427;&#12290;<\/p><h2>&#26041;&#27861;&#19968;&#65306;&#20351;&#29992;<code>view<\/code>&#20316;&#26354;&#23478;<\/h2><p>&#23545;&#19981;&#36215;&#65292;&#25105;&#19981;&#26126;&#30333;&#20320;&#22312;&#35828;&#20160;&#20040;&#12290;<code>view<\/code>Composer &#21487;&#20197;&#29992;&#20110;&#23558;&#25968;&#25454;&#32465;&#23450;&#21040;&#25152;&#26377;&#35270;&#22270;&#12290;<\/p><pre><code>View::composer('*', function ($view) {\n    $view-&gt;with('globalVariable', 'This is a global variable');\n});\n<\/code><\/pre><p>&#29616;&#22312;&#65292;&#22312;&#20219;&#20309;Blade&#27169;&#26495;&#20013;&#65292;&#37117;&#21487;&#20197;&#35775;&#38382;<code>$globalVariable<\/code>&#25910;&#21040;<\/p><pre><code>{{ $globalVariable }}\n<\/code><\/pre><h2>&#26041;&#27861;2&#65306;&#20351;&#29992;&#26381;&#21153;&#25552;&#20379;&#21830;&#20849;&#20139;&#25968;&#25454;<\/h2><p>&#21478;&#19968;&#31181;&#23450;&#20041;&#20840;&#23616;&#21464;&#37327;&#30340;&#26041;&#24335;&#26159;&#20351;&#29992;&#26381;&#21153;&#25552;&#20379;&#32773;&#12290;<\/p><pre><code>public function boot() {\n    view()-&gt;share('globalVariable', 'This is a global variable');\n}\n<\/code><\/pre><p>&#22312;&#35270;&#22270;&#20013;&#65292;&#20320;&#21487;&#20197;&#20687;&#35775;&#38382;&#20854;&#20182;&#21464;&#37327;&#19968;&#26679;&#35775;&#38382;&#23427;&#65306;<\/p><pre><code>{{ $globalVariable }}\n<\/code><\/pre><h2>&#26041;&#27861; 3&#65306;&#29615;&#22659;&#37197;&#32622;<\/h2><p>&#29615;&#22659;&#21464;&#37327;&#21487;&#20197;&#22312;&#20854;&#20013;&#35774;&#32622;&#12290;<code>.env<\/code>&#22312;Blade&#27169;&#26495;&#20013;&#20351;&#29992;&#25991;&#20214;&#21644;&#35775;&#38382;&#23427;&#20204;&#30340;&#12290;<code>env<\/code>&#21151;&#33021;&#12290;<\/p><pre><code>APP_GLOBAL_VARIABLE=\"A global value from .env\"\n<\/code><\/pre><p>&#22312;&#20320;&#30340;Blade&#27169;&#26495;&#20013;&#20351;&#29992;&#65306;<\/p><pre><code>{{ env('APP_GLOBAL_VARIABLE') }}\n<\/code><\/pre><h2>&#26041;&#27861;4&#65306;&#21019;&#24314;&#19968;&#20010;Blade&#25351;&#20196;<\/h2><p>&#23450;&#21046;&#30340;Blade&#25351;&#20196;&#21487;&#20197;&#25552;&#20379;&#19968;&#20010;&#21487;&#37325;&#29992;&#30340;&#20195;&#30721;&#29255;&#27573;&#65292;&#21487;&#20197;&#22312;&#20219;&#20309;&#27169;&#26495;&#20013;&#20351;&#29992;&#12290;<\/p><pre><code>Blade::directive('globalVariable', function () {\n    return 'This is a global variable';\n});\n<\/code><\/pre><p>&#28982;&#21518;&#22312;&#27169;&#26495;&#20013;&#20351;&#29992;&#33258;&#23450;&#20041;&#25351;&#20196;&#65306;<\/p><pre><code>@globalVariable\n<\/code><\/pre><h2>&#26041;&#27861; 5&#65306;&#20351;&#29992;&#22522;&#30784;&#35270;&#22270;<\/h2><p>&#22522;&#30784;&#30340;Blade&#27169;&#26495;&#21487;&#20197;&#29992;&#26469;&#23450;&#20041;&#21464;&#37327;&#65292;&#36825;&#20123;&#21464;&#37327;&#21487;&#20197;&#22312;&#20854;&#20182;&#35270;&#22270;&#20013;&#25193;&#23637;&#20351;&#29992;&#12290;<\/p><pre><code>\/\/ resources\/views\/layouts\/app.blade.php\n@section('globalVariableSection')\nThis is the content of the global variable section.\n@endsection\n<\/code><\/pre><p>&#22312;&#23376;&#35270;&#22270;&#20013;&#65306;<\/p><pre><code>@extends('layouts.app')\n@section('globalVariableSection')\n@parent\nAdditional content for the section.\n@endsection\n<\/code><\/pre><h2>&#39640;&#32423;&#26041;&#27861;<\/h2><h3>&#20351;&#29992;&#20013;&#38388;&#20214;<\/h3><p>&#20013;&#38388;&#20214;&#21487;&#20197;&#29992;&#20110;&#22312;&#27599;&#27425;HTTP&#35831;&#27714;&#19978;&#32465;&#23450;&#25968;&#25454;&#21040;&#35270;&#22270;&#19978;&#12290;<\/p><pre><code>public function handle($request, Closure $next)\n{\n    view()-&gt;share('globalVariable', 'This is set by middleware');\n    return $next($request);\n}\n<\/code><\/pre><p>&#28982;&#21518;&#65292;&#27880;&#20876;&#20320;&#30340;&#20013;&#38388;&#20214;&#21040;&#12290;<code>web<\/code>&#22312;&#32676;&#20307;&#20869;&#12290;<code>app\/Http\/Kernel.php<\/code>&#25991;&#20214;&#12290;<\/p><h3>&#20840;&#23616;&#21464;&#37327;&#23545;&#20110;&#29305;&#23450;&#35270;&#22270;&#12290;<\/h3><p>&#20320;&#21487;&#20197;&#20351;&#29992;&#27169;&#24335;&#23558;&#25968;&#25454;&#32465;&#23450;&#21040;&#29305;&#23450;&#30340;&#35270;&#22270;&#19978;&#12290;<\/p><pre><code>View::composer(['profile', 'dashboard'], function ($view) {\n    $view-&gt;with('globalVariable', 'Specific for some views');\n});\n<\/code><\/pre><p>&#20174;&#29616;&#22312;&#36215;&#65292;&#32771;&#34385;&#21040;<code>profile.blade.php<\/code>and &#26159;&ldquo;&#24182;&#19988;&rdquo;&#30340;&#24847;&#24605;&#65292;&#29992;&#20110;&#36830;&#25509;&#20004;&#20010;&#24182;&#21015;&#30340;&#21477;&#23376;&#25110;&#30701;&#35821;&#12290;<code>dashboard.blade.php<\/code>&#27491;&#24120;&#20351;&#29992;&#21363;&#21487;&#65306;<\/p><pre><code>{{ $globalVariable }}\n<\/code><\/pre><h3>&#20351;&#29992;&#21333;&#20363;&#27169;&#24335;<\/h3><p>&#20320;&#21487;&#20197;&#36890;&#36807;Laravel&#30340;&#23481;&#22120;&#32465;&#23450;&#35774;&#32622;&#20840;&#23616;&#21464;&#37327;&#65292;&#20351;&#20854;&#25104;&#20026;&#21333;&#20363;&#27169;&#24335;&#12290;<\/p><pre><code>App::singleton('globalVariable', function () {\n    return 'This is a global variable as a singleton';\n});\n<\/code><\/pre><p>&#22312;Blade&#27169;&#26495;&#20013;&#65292;&#21487;&#20197;&#36890;&#36807;&#20197;&#19979;&#26041;&#24335;&#35775;&#38382;&#23427;&#65306;<\/p><pre><code>{{ App::make('globalVariable') }}\n<\/code><\/pre><h2>&#32467;&#35770;&#12290;<\/h2><p>&#24635;&#32467;&#19968;&#19979;&#65292;&#20840;&#23616;&#21464;&#37327;&#20026;Laravel&#24212;&#29992;&#31243;&#24207;&#20013;&#30340;&#19981;&#21516;&#35270;&#22270;&#20849;&#20139;&#24120;&#35265;&#25968;&#25454;&#25552;&#20379;&#20102;&#19968;&#20010;&#26041;&#20415;&#30340;&#26041;&#27861;&#12290;&#20363;&#22914;&#65292;&#21487;&#20197;&#20351;&#29992;use&#35821;&#21477;&#26469;&#24341;&#29992;&#20840;&#23616;&#21464;&#37327;&#12290;<code>view<\/code>Composer &#21644;&#29615;&#22659;&#21464;&#37327;&#65292;&#21019;&#24314;&#20855;&#26377;&#26381;&#21153;&#25552;&#20379;&#32773;&#21644;&#33258;&#23450;&#20041;&#25351;&#31034;&#31526;&#30340;&#20581;&#22766;&#21487;&#37325;&#29992;&#20195;&#30721;&#65292;&#26681;&#25454;&#39033;&#30446;&#38656;&#27714;&#65292;&#24744;&#26377;&#22810;&#31181;&#36873;&#25321;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--3\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/xygcfznnzczhsdmwydzhsmzzzmddnq-400x300.jpg\" alt=\"&#38271;&#24037;&#30721;&#22900;1523\" class=\"wp-image-2906\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#38271;&#24037;&#30721;&#22900;1523<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>Laravel &#26159;&#19968;&#20010;&#38750;&#24120;&#27969;&#34892;&#30340; PHP &#24320;&#21457;&#26694;&#26550;&#65292;&#23427;&#25552;&#20379;&#20102;&#35768;&#22810;&#20869;&#32622;&#21151;&#33021;&#26469;&#31616;&#21270;&#27169;&#26495;&#28210;&#26579;&#21644;&#25968;&#25454;&#22788;&#29702;&#12290;&#22312; Laravel &#20013;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992; <code>$this<\/code> &#20851;&#38190;&#23383;&#26469;&#35775;&#38382;&#24403;&#21069;&#25511;&#21046;&#22120;&#30340;&#23454;&#20363;&#65292;&#24182;&#36890;&#36807; <code>$request<\/code> &#33719;&#21462;&#35831;&#27714;&#23545;&#35937;&#12290;<\/p>\n<p>&#35201;&#22312; Blade &#27169;&#26495;&#20013;&#20351;&#29992;&#20840;&#23616;&#21464;&#37327;&#65292;&#35831;&#25353;&#29031;&#20197;&#19979;&#27493;&#39588;&#25805;&#20316;&#65306;<\/p>\n<ol>\n<li>\n<p>&#22312;&#25511;&#21046;&#22120;&#20013;&#23450;&#20041;&#20840;&#23616;&#21464;&#37327;&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\nnamespace AppHttpControllers;\n\nuse IlluminateHttpRequest;\nuse AppGlobalVariable;\n\nclass UserController extends Controller {\n   protected $globalVar;\n\n   public function __construct(GlobalVariable $globalVar) {\n       $this-&gt;globalVar = $globalVar;\n   }\n\n   public function index() {\n       return view('users.index', [\n           'globalVar' =&gt; $this-&gt;globalVar,\n       ]);\n   }\n}<\/code><\/pre>\n<\/li>\n<li>&#22312;&#27169;&#26495;&#25991;&#20214;&#65288;&#20363;&#22914; <code>app.blade.php<\/code>&#65289;&#20013;&#20351;&#29992; <code>$this-&gt;globalVar<\/code>&#65306;\n<pre><code class=\"language-blade\">@section('content')\n   &lt;div&gt;{{ $this-&gt;globalVar }}&lt;\/div&gt;\n@endsection<\/code><\/pre><\/li>\n<\/ol>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;&#25105;&#20204;&#21019;&#24314;&#20102;&#19968;&#20010;&#21517;&#20026; <code>GlobalVariable<\/code> &#30340;&#27169;&#22411;&#65292;&#24182;&#23558;&#20854;&#27880;&#20837;&#21040;&#25511;&#21046;&#22120;&#26500;&#36896;&#20989;&#25968;&#20013;&#12290;&#28982;&#21518;&#65292;&#22312;&#27169;&#26495;&#20013;&#20351;&#29992; <code>$this-&gt;globalVar<\/code> &#26469;&#33719;&#21462;&#20840;&#23616;&#21464;&#37327;&#12290;<\/p>\n<p>&#36825;&#31181;&#26041;&#27861;&#30340;&#20248;&#28857;&#26159;&#31616;&#27905;&#19988;&#26131;&#20110;&#32500;&#25252;&#65292;&#20294;&#32570;&#28857;&#26159;&#22914;&#26524;&#20840;&#23616;&#21464;&#37327;&#30340;&#20540;&#21457;&#29983;&#21464;&#21270;&#65292;&#20320;&#38656;&#35201;&#25163;&#21160;&#26356;&#26032;&#25972;&#20010;&#24212;&#29992;&#20013;&#30340;&#25152;&#26377;&#35270;&#22270;&#12290;&#21478;&#19968;&#31181;&#26041;&#27861;&#26159;&#22312;&#27599;&#27425;&#38656;&#35201;&#20351;&#29992;&#20840;&#23616;&#21464;&#37327;&#26102;&#37117;&#20256;&#36882;&#19968;&#20010;&#24341;&#29992;&#65292;&#36825;&#26679;&#21363;&#20351;&#20840;&#23616;&#21464;&#37327;&#30340;&#20540;&#21464;&#21270;&#20102;&#65292;&#20320;&#20063;&#21482;&#38656;&#35201;&#20462;&#25913;&#36825;&#20010;&#24341;&#29992;&#21363;&#21487;&#12290;<\/p>\n<pre><code class=\"language-blade\">@section('content')\n    &lt;div&gt;{{ $globalVar }}&lt;\/div&gt;\n@endsection<\/code><\/pre>\n<p>&#36825;&#31181;&#26041;&#24335;&#21487;&#20197;&#36991;&#20813;&#19981;&#24517;&#35201;&#30340;&#26356;&#25913;&#65292;&#20294;&#23545;&#20110;&#36739;&#22823;&#30340;&#39033;&#30446;&#65292;&#36825;&#21487;&#33021;&#20250;&#22686;&#21152;&#19968;&#20123;&#22797;&#26434;&#24615;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312; Laravel &#20013;&#65292;&#20320;&#21487;&#20197;&#36890;&#36807;&#22810;&#31181;&#26041;&#24335;&#22312; Blade &#27169;&#038;#26..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[44],"tuisongtax":[],"class_list":["post-762","my1js","type-my1js","status-publish","hentry","my1js2nav-laravel"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=762"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=762"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=762"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}