<article><h1>Laravel 的 Facades 介绍</h1><ul><li><a href="#introduction">简介</a></li><li><a href="#when-to-use-facades">何时使用 Facades</a><ul><li><a href="#facades-vs-dependency-injection">Facades Vs. 依赖注入</a></li><li><a href="#facades-vs-helper-functions">Facades Vs. 辅助函数</a></li></ul></li><li><a href="#how-facades-work">Facades 工作原理</a></li><li><a href="#facade-class-reference">Facade 类参考</a></li></ul><p><a name="introduction"></a></p><h2><a href="#introduction">简介</a></h2><p>Facades(读音:/fəˈsäd/ )为应用程序的 <a href="/docs/5.4/container">服务容器</a> 中可用的类提供了一个「静态」接口。Laravel 自带了很多 facades ,几乎可以用来访问到 Laravel 中所有的服务。Laravel facades 实际上是服务容器中那些底层类的「静态代理」,相比于传统的静态方法, facades 在提供了简洁且丰富的语法同时,还带来了更好的可测试性和扩展性。</p><p>所有的 Laravel facades 都需要定义在命名空间 <code class=" language-php">Illuminate\<span class="token package">Support<span class="token punctuation">\</span>Facades</span></code> 下。所以,我们可以容易地向下面这样调用 facade :</p><pre class=" language-php"><code class=" language-php"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Cache</span><span class="token punctuation">;</span>
<span class="token scope">Route<span class="token punctuation">::</span></span><span class="token function">get<span class="token punctuation">(</span></span><span class="token string">'/cache'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token scope">Cache<span class="token punctuation">::</span></span><span class="token function">get<span class="token punctuation">(</span></span><span class="token string">'key'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><p>在 Laravel 的文档中,很多示例代码都是使用 facades 来演示框架的各种特性的。</p><p><a name="when-to-use-facades"></a></p><h2><a href="#when-to-use-facades">何时使用 Facades</a></h2><p>Facades 有很多好处,它为我们使用 Laravel 的各种功能提供了简单,易记的语法,让你不需要记住长长的类名来实现依赖注入和手动配置。还有,因为它们对于PHP动态方法的独特用法,测试起来非常容易。</p><p>然而,在使用 facades 时,有些地方还需要特别注意。使用 facades 最主要的风险就是会引起类作用范围的膨胀。因为 facades 使用起来非常简单而且不需要注入,我们会不经意的在单个类中大量使用。它不会像使用依赖注入那样,使用的类越多,构造方法会越长,在视觉上就会引起注意,提醒你这个类有点庞大了。所以在使用 facades 的时候,要特别注意控制好类的大小,让类的作用范围保持短小。</p><blockquote class="has-icon tip"><p><div class="flag"><span class="svg"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" version="1.1" x="0px" y="0px" width="56.6px" height="87.5px" viewBox="0 0 56.6 87.5" enable-background="new 0 0 56.6 87.5" xml:space="preserve"><path fill="#FFFFFF" d="M28.7 64.5c-1.4 0-2.5-1.1-2.5-2.5v-5.7 -5V41c0-1.4 1.1-2.5 2.5-2.5s2.5 1.1 2.5 2.5v10.1 5 5.8C31.2 63.4 30.1 64.5 28.7 64.5zM26.4 0.1C11.9 1 0.3 13.1 0 27.7c-0.1 7.9 3 15.2 8.2 20.4 0.5 0.5 0.8 1 1 1.7l3.1 13.1c0.3 1.1 1.3 1.9 2.4 1.9 0.3 0 0.7-0.1 1.1-0.2 1.1-0.5 1.6-1.8 1.4-3l-2-8.4 -0.4-1.8c-0.7-2.9-2-5.7-4-8 -1-1.2-2-2.5-2.7-3.9C5.8 35.3 4.7 30.3 5.4 25 6.7 14.5 15.2 6.3 25.6 5.1c13.9-1.5 25.8 9.4 25.8 23 0 4.1-1.1 7.9-2.9 11.2 -0.8 1.4-1.7 2.7-2.7 3.9 -2 2.3-3.3 5-4 8L41.4 53l-2 8.4c-0.3 1.2 0.3 2.5 1.4 3 0.3 0.2 0.7 0.2 1.1 0.2 1.1 0 2.2-0.8 2.4-1.9l3.1-13.1c0.2-0.6 0.5-1.2 1-1.7 5-5.1 8.2-12.1 8.2-19.8C56.4 12 42.8-1 26.4 0.1zM43.7 69.6c0 0.5-0.1 0.9-0.3 1.3 -0.4 0.8-0.7 1.6-0.9 2.5 -0.7 3-2 8.6-2 8.6 -1.3 3.2-4.4 5.5-7.9 5.5h-4.1H28h-0.5 -3.6c-3.5 0-6.7-2.4-7.9-5.7l-0.1-0.4 -1.8-7.8c-0.4-1.1-0.8-2.1-1.2-3.1 -0.1-0.3-0.2-0.5-0.2-0.9 0.1-1.3 1.3-2.1 2.6-2.1H41C42.4 67.5 43.6 68.2 43.7 69.6zM37.7 72.5H26.9c-4.2 0-7.2 3.9-6.3 7.9 0.6 1.3 1.8 2.1 3.2 2.1h4.1 0.5 0.5 3.6c1.4 0 2.7-0.8 3.2-2.1L37.7 72.5z"></path></svg></span></div> 在开发与 Laravel 交互的第三方扩展包时,最好是在包中通过注入 <a href="/docs/5.4/contracts">Laravel contracts</a> ,而不是在包中通过 facades 来使用 Laravel 的类。因为扩展包不是在 Laravel 内部使用的,无法使用 Laravel's facade 的测试辅助函数。</p></blockquote><p><a name="facades-vs-dependency-injection"></a></p><h3>Facades Vs. 依赖注入</h3><p>依赖注入的一个主要的好处是可以切换注入类的具体实现。这在测试的时候很有用,因为你可以注入一个 mock 或者 stub ,并且对在 stub 中被调用的各种方法进行断言。</p><p>通常,静态方法是不可以被 mock 或者 stub 。但是,因为 facades 调用的是对象的动态方法,我们可以像测试注入类的实例一样测试 facades ,例如,像下面的路由:</p><pre class=" language-php"><code class=" language-php"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Cache</span><span class="token punctuation">;</span>
<span class="token scope">Route<span class="token punctuation">::</span></span><span class="token function">get<span class="token punctuation">(</span></span><span class="token string">'/cache'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token scope">Cache<span class="token punctuation">::</span></span><span class="token function">get<span class="token punctuation">(</span></span><span class="token string">'key'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><p>我们可以用下面的测试代码去验证 <code class=" language-php"><span class="token scope">Cache<span class="token punctuation">::</span></span>get</code> 方法是否被调用,当传入预期的参数时。</p><pre class=" language-php"><code class=" language-php"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Cache</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">/**
* 一个基础功能的测试用例。
*
* @return void
*/</span>
<span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">testBasicExample<span class="token punctuation">(</span></span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token scope">Cache<span class="token punctuation">::</span></span><span class="token function">shouldReceive<span class="token punctuation">(</span></span><span class="token string">'get'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">with<span class="token punctuation">(</span></span><span class="token string">'key'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">andReturn<span class="token punctuation">(</span></span><span class="token string">'value'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token this">$this</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">visit<span class="token punctuation">(</span></span><span class="token string">'/cache'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">see<span class="token punctuation">(</span></span><span class="token string">'value'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre><p><a name="facades-vs-helper-functions"></a></p><h3>Facades Vs. 辅助函数</h3><p>除了 facades , Laravel 包含一些「辅助函数」来实现一些常用的功能,比如生成视图,触发事件,调度任务或者发送 HTTP 响应。许多辅助函数的功能和对应的 facades 一样。例如,下面这个 facade 和辅助函数的作用是一样的:</p><pre class=" language-php"><code class=" language-php"><span class="token keyword">return</span> <span class="token scope">View<span class="token punctuation">::</span></span><span class="token function">make<span class="token punctuation">(</span></span><span class="token string">'profile'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">return</span> <span class="token function">view<span class="token punctuation">(</span></span><span class="token string">'profile'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><p>这里的 facades 和辅助函数是没有任何区别的。当你使用辅助函数时,你依然可以向使用对应的 facade 一样测试他们。例如,下面的路由:</p><pre class=" language-php"><code class=" language-php"><span class="token scope">Route<span class="token punctuation">::</span></span><span class="token function">get<span class="token punctuation">(</span></span><span class="token string">'/cache'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token function">cache<span class="token punctuation">(</span></span><span class="token string">'key'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><p>在底层,辅助函数 <code class=" language-php">cache</code> 实际是调用 <code class=" language-php">Cache</code> facade 中的 <code class=" language-php">get</code> 方法。因此,尽管我们是在使用辅助函数,我们依然可以用下面的测试代码来验证是否方法被正确调用,在传入预期的参数时:</p><pre class=" language-php"><code class=" language-php"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Cache</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">/**
* 一个基础功能的测试用例。
*
* @return void
*/</span>
<span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">testBasicExample<span class="token punctuation">(</span></span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token scope">Cache<span class="token punctuation">::</span></span><span class="token function">shouldReceive<span class="token punctuation">(</span></span><span class="token string">'get'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">with<span class="token punctuation">(</span></span><span class="token string">'key'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">andReturn<span class="token punctuation">(</span></span><span class="token string">'value'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token this">$this</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">visit<span class="token punctuation">(</span></span><span class="token string">'/cache'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">see<span class="token punctuation">(</span></span><span class="token string">'value'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre><p><a name="how-facades-work"></a></p><h2><a href="#how-facades-work">Facades 工作原理</a></h2><p>在 Laravel 应用中,一个 facade 就是一个提供访问容器中对象的类。其中核心的部件就是 <code class=" language-php">Facade</code> 类。不管是 Laravel 自带的 Facades ,还是用户自定义的 Facades ,都继承自 <code class=" language-php">Illuminate\<span class="token package">Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Facade</span></code> 类。</p><p><code class=" language-php">Facade</code> 基类使用 <code class=" language-php"><span class="token function">__callStatic<span class="token punctuation">(</span></span><span class="token punctuation">)</span></code> 魔术方法在你的 facades 中延迟调用容器中对应对象的方法,在下面的例子中,调用了 Laravel 的缓存系统。在代码里,我们可能认为是 <code class=" language-php">Cache</code> 类中的静态方法 <code class=" language-php">get</code> 被调用了:</p><pre class=" language-php"><code class=" language-php"><span class="token delimiter"><?php</span>
<span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Controllers</span><span class="token punctuation">;</span></code></pre><p> use Illuminate\Support\Facades\Cache; use App\Http\Controllers\Controller;</p><pre class=" language-php"><code class=" language-php"><span class="token keyword">class</span> <span class="token class-name">UserController</span> <span class="token keyword">extends</span> <span class="token class-name">Controller</span>
<span class="token punctuation">{</span>
<span class="token comment" spellcheck="true">/**
* 显示给定用户的大体信息。
*
* @param int $id
* @return Response
*/</span>
<span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">showProfile<span class="token punctuation">(</span></span><span class="token variable">$id</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token variable">$user</span> <span class="token operator">=</span> <span class="token scope">Cache<span class="token punctuation">::</span></span><span class="token function">get<span class="token punctuation">(</span></span><span class="token string">'user:'</span><span class="token punctuation">.</span><span class="token variable">$id</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">return</span> <span class="token function">view<span class="token punctuation">(</span></span><span class="token string">'profile'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">'user'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$user</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre><p>注意在代码的最上面,我们导入的是 <code class=" language-php">Cache</code> facade 。这个 facade 其实是我们获取底层 <code class=" language-php">Illuminate\<span class="token package">Contracts<span class="token punctuation">\</span>Cache<span class="token punctuation">\</span>Factory</span></code> 接口实现的一个代理。我们通过这个 facade 调用的任何方法,都会被传递到 Laravel 缓存服务的底层实例中。</p><p>如果我们看一下 <code class=" language-php">Illuminate\<span class="token package">Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Cache</span></code> 这个类,你会发现类中根本没有 <code class=" language-php">get</code> 这个静态方法:</p><pre class=" language-php"><code class=" language-php"><span class="token keyword">class</span> <span class="token class-name">Cache</span> <span class="token keyword">extends</span> <span class="token class-name">Facade</span>
<span class="token punctuation">{</span>
<span class="token comment" spellcheck="true">/**
* 获取组件在容器中注册的名称。
*
* @return string
*/</span>
<span class="token keyword">protected</span> <span class="token keyword">static</span> <span class="token keyword">function</span> <span class="token function">getFacadeAccessor<span class="token punctuation">(</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token string">'cache'</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre><p>其实, <code class=" language-php">Cache</code> facade 是继承了 <code class=" language-php">Facade</code> 基类,并且定义了 <code class=" language-php"><span class="token function">getFacadeAccessor<span class="token punctuation">(</span></span><span class="token punctuation">)</span></code> 方法。这个方法的作用是返回服务容器中对应名字的绑定内容。当用户调用 <code class=" language-php">Cache</code> facade 中的任何静态方法时, Laravel 会解析到服务容器中绑定的键值为 <code class=" language-php">cache</code> 实例对象,并调用这个对象对应的方法(在这个例子中就是 <code class=" language-php">get</code> 方法)。</p><p><a name="facade-class-reference"></a></p><h2><a href="#facade-class-reference">Facade 类参考</a></h2><p>在下面你可以找到每个 facade 类及其对应的底层类。这是一个查找给定 facade 类 API 文档的有用工具。 也列出了绑定在 <a href="/docs/5.4/container">服务容器</a> 中 facade 类对应的可用键值。</p><table><thead><tr><th>Facade</th><th>Class</th><th>Service Container Binding</th></tr></thead><tbody><tr><td>App</td><td><a href="https://laravel.com/api/5.4/Illuminate/Foundation/Application.html">Illuminate\Foundation\Application</a></td><td><code class=" language-php">app</code></td></tr><tr><td>Artisan</td><td><a href="https://laravel.com/api/5.4/Illuminate/Contracts/Console/Kernel.html">Illuminate\Contracts\Console\Kernel</a></td><td><code class=" language-php">artisan</code></td></tr><tr><td>Auth</td><td><a href="https://laravel.com/api/5.4/Illuminate/Auth/AuthManager.html">Illuminate\Auth\AuthManager</a></td><td><code class=" language-php">auth</code></td></tr><tr><td>Blade</td><td><a href="https://laravel.com/api/5.4/Illuminate/View/Compilers/BladeCompiler.html">Illuminate\View\Compilers\BladeCompiler</a></td><td><code class=" language-php">blade<span class="token punctuation">.</span>compiler</code></td></tr><tr><td>Bus</td><td><a href="https://laravel.com/api/5.4/Illuminate/Contracts/Bus/Dispatcher.html">Illuminate\Contracts\Bus\Dispatcher</a></td><td> </td></tr><tr><td>Cache</td><td><a href="https://laravel.com/api/5.4/Illuminate/Cache/Repository.html">Illuminate\Cache\Repository</a></td><td><code class=" language-php">cache</code></td></tr><tr><td>Config</td><td><a href="https://laravel.com/api/5.4/Illuminate/Config/Repository.html">Illuminate\Config\Repository</a></td><td><code class=" language-php">config</code></td></tr><tr><td>Cookie</td><td><a href="https://laravel.com/api/5.4/Illuminate/Cookie/CookieJar.html">Illuminate\Cookie\CookieJar</a></td><td><code class=" language-php">cookie</code></td></tr><tr><td>Crypt</td><td><a href="https://laravel.com/api/5.4/Illuminate/Encryption/Encrypter.html">Illuminate\Encryption\Encrypter</a></td><td><code class=" language-php">encrypter</code></td></tr><tr><td>DB</td><td><a href="https://laravel.com/api/5.4/Illuminate/Database/DatabaseManager.html">Illuminate\Database\DatabaseManager</a></td><td><code class=" language-php">db</code></td></tr><tr><td>DB (Instance)</td><td><a href="https://laravel.com/api/5.4/Illuminate/Database/Connection.html">Illuminate\Database\Connection</a></td><td> </td></tr><tr><td>Event</td><td><a href="https://laravel.com/api/5.4/Illuminate/Events/Dispatcher.html">Illuminate\Events\Dispatcher</a></td><td><code class=" language-php">events</code></td></tr><tr><td>File</td><td><a href="https://laravel.com/api/5.4/Illuminate/Filesystem/Filesystem.html">Illuminate\Filesystem\Filesystem</a></td><td><code class=" language-php">files</code></td></tr><tr><td>Gate</td><td><a href="https://laravel.com/api/5.4/Illuminate/Contracts/Auth/Access/Gate.html">Illuminate\Contracts\Auth\Access\Gate</a></td><td> </td></tr><tr><td>Hash</td><td><a href="https://laravel.com/api/5.4/Illuminate/Contracts/Hashing/Hasher.html">Illuminate\Contracts\Hashing\Hasher</a></td><td><code class=" language-php">hash</code></td></tr><tr><td>Lang</td><td><a href="https://laravel.com/api/5.4/Illuminate/Translation/Translator.html">Illuminate\Translation\Translator</a></td><td><code class=" language-php">translator</code></td></tr><tr><td>Log</td><td><a href="https://laravel.com/api/5.4/Illuminate/Log/Writer.html">Illuminate\Log\Writer</a></td><td><code class=" language-php">log</code></td></tr><tr><td>Mail</td><td><a href="https://laravel.com/api/5.4/Illuminate/Mail/Mailer.html">Illuminate\Mail\Mailer</a></td><td><code class=" language-php">mailer</code></td></tr><tr><td>Notification</td><td><a href="https://laravel.com/api/5.4/Illuminate/Notifications/ChannelManager.html">Illuminate\Notifications\ChannelManager</a></td><td> </td></tr><tr><td>Password</td><td><a href="https://laravel.com/api/5.4/Illuminate/Auth/Passwords/PasswordBrokerManager.html">Illuminate\Auth\Passwords\PasswordBrokerManager</a></td><td><code class=" language-php">auth<span class="token punctuation">.</span>password</code></td></tr><tr><td>Queue</td><td><a href="https://laravel.com/api/5.4/Illuminate/Queue/QueueManager.html">Illuminate\Queue\QueueManager</a></td><td><code class=" language-php">queue</code></td></tr><tr><td>Queue (Instance)</td><td><a href="https://laravel.com/api/5.4/Illuminate/Contracts/Queue/Queue.html">Illuminate\Contracts\Queue\Queue</a></td><td><code class=" language-php">queue</code></td></tr><tr><td>Queue (Base Class)</td><td><a href="https://laravel.com/api/5.4/Illuminate/Queue/Queue.html">Illuminate\Queue\Queue</a></td><td> </td></tr><tr><td>Redirect</td><td><a href="https://laravel.com/api/5.4/Illuminate/Routing/Redirector.html">Illuminate\Routing\Redirector</a></td><td><code class=" language-php">redirect</code></td></tr><tr><td>Redis</td><td><a href="https://laravel.com/api/5.4/Illuminate/Redis/Database.html">Illuminate\Redis\Database</a></td><td><code class=" language-php">redis</code></td></tr><tr><td>Request</td><td><a href="https://laravel.com/api/5.4/Illuminate/Http/Request.html">Illuminate\Http\Request</a></td><td><code class=" language-php">request</code></td></tr><tr><td>Response</td><td><a href="https://laravel.com/api/5.4/Illuminate/Contracts/Routing/ResponseFactory.html">Illuminate\Contracts\Routing\ResponseFactory</a></td><td> </td></tr><tr><td>Route</td><td><a href="https://laravel.com/api/5.4/Illuminate/Routing/Router.html">Illuminate\Routing\Router</a></td><td><code class=" language-php">router</code></td></tr><tr><td>Schema</td><td><a href="https://laravel.com/api/5.4/Illuminate/Database/Schema/Blueprint.html">Illuminate\Database\Schema\Blueprint</a></td><td> </td></tr><tr><td>Session</td><td><a href="https://laravel.com/api/5.4/Illuminate/Session/SessionManager.html">Illuminate\Session\SessionManager</a></td><td><code class=" language-php">session</code></td></tr><tr><td>Session (Instance)</td><td><a href="https://laravel.com/api/5.4/Illuminate/Session/Store.html">Illuminate\Session\Store</a></td><td> </td></tr><tr><td>Storage</td><td><a href="https://laravel.com/api/5.4/Illuminate/Contracts/Filesystem/Factory.html">Illuminate\Contracts\Filesystem\Factory</a></td><td><code class=" language-php">filesystem</code></td></tr><tr><td>URL</td><td><a href="https://laravel.com/api/5.4/Illuminate/Routing/UrlGenerator.html">Illuminate\Routing\UrlGenerator</a></td><td><code class=" language-php">url</code></td></tr><tr><td>Validator</td><td><a href="https://laravel.com/api/5.4/Illuminate/Validation/Factory.html">Illuminate\Validation\Factory</a></td><td><code class=" language-php">validator</code></td></tr><tr><td>Validator (Instance)</td><td><a href="https://laravel.com/api/5.4/Illuminate/Validation/Validator.html">Illuminate\Validation\Validator</a></td><td> </td></tr><tr><td>View</td><td><a href="https://laravel.com/api/5.4/Illuminate/View/Factory.html">Illuminate\View\Factory</a></td><td><code class=" language-php">view</code></td></tr><tr><td>View (Instance)</td><td><a href="https://laravel.com/api/5.4/Illuminate/View/View.html">Illuminate\View\View</a></td><td> </td></tr></tbody></table></article>
- 入门指南
- 安装
- 配置信息
- 文件夹结构
- 请求周期
- 开发环境部署
- Valet
- Homestead
- 核心概念
- 服务提供者
- Facades
- Contracts
- 服务容器
- HTTP 层
- 路由
- 中间件
- CSRF 保护
- 控制器
- 请求
- 响应
- 视图
- Session
- 表单验证
- 前端
- Blade 模板
- 本地化
- 前端指南
- 编辑资源 Mix
- 安全
- API 认证
- 用户认证
- 用户授权
- 加密解密
- 哈希
- 重置密码
- 数据库
- 快速入门
- 查询构造器
- 分页
- 数据库迁移
- Redis
- 数据填充
- Eloquent ORM
- Eloquent ORM快速入门
- 模型关联
- Eloquent 集合
- 修改器
- 序列化
- 综合话题
- Artisan 命令行
- 广播系统
- 缓存系统
- 集合
- 错误与日志
- 事件系统
- 文件存储
- 辅助函数
- 邮件发送
- 消息通知
- 扩展包开发
- 队列
- 任务调度