<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 序言 —— 升級指南 ## 更新到?5.1.11 Laravel?5.1.11包含了對授權和策略的支持,將這些新特性整合到已經存在的Laravel 5.1中很簡單。 > 注意:這些更新是可選的,忽略它們并不影響你的應用。 ### 創建策略類目錄 首先,在應用中創建一個空的`app/Policies`目錄。 ### 創建/注冊AuthServiceProvider & Gate門面 在`app/Providers`目錄下創建`AuthServiceProvider`,你可以從[GitHub](https://raw.githubusercontent.com/laravel/laravel/master/app/Providers/AuthServiceProvider.php)上拷貝該默認提供者的內容,創建完成后,確保在配置文件`app.php`的`providers`數組中注冊該提供者。 此外,還要在配置文件`app.php`的`aliases`數組中注冊`Gate`[門面](http://laravelacademy.org/post/97.html): ~~~ 'Gate' => Illuminate\Support\Facades\Gate::class, ~~~ ### 更新User模型 然后,在`App\User`?模型中使用?`Illuminate\Foundation\Auth\Access\Authorizable`?trait并實現`Illuminate\Contracts\Auth\Access\Authorizable`契約: ~~~ <?php namespace App; use Illuminate\Auth\Authenticatable; use Illuminate\Database\Eloquent\Model; use Illuminate\Auth\Passwords\CanResetPassword; use Illuminate\Foundation\Auth\Access\Authorizable; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract { use Authenticatable, Authorizable, CanResetPassword; } ~~~ ### 更新基類控制器 接下來,更新基類控制器`App\Http\Controllers\Controller`以便可以使用`Illuminate\Foundation\Auth\Access\AuthorizesRequests`trait: ~~~ <?php namespace App\Http\Controllers; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; abstract class Controller extends BaseController{ use AuthorizesRequests, DispatchesJobs, ValidatesRequests; } ~~~ ## 升級到5.1.0 **預計更新時間:小于1小時** ### 更新bootstrap/autoload.php 更新`bootstrap/autoload.php`中的變量$compilePath: ~~~ $compiledPath = __DIR__.'/cache/compiled.php'; ~~~ ### 創建bootstrap/cache目錄 在`bootstrap`目錄中,創建`cache`目錄,在該目錄中創建一個`.gitignore`文件,編輯文件內容如下: ~~~ *!.gitignore ~~~ 該目錄應該是可寫的,用來存儲臨時優化文件如`compiled.php`,`routes.php`,`config.php`以及`service.json` ### 新增BroadcastServiceProvider 在配置文件`config/app.php`中,添加`Illuminate\Broadcasting\BroadcastServiceProvider`到`providers`數組。 ### 認證 如果你在使用Laravel自帶的`AuthenticatesAndRegistersUsers`的`AuthController`,則需要對新用戶的驗證和創建做一些代碼改動: 首先,你不再需要傳遞`Guard`和`Register`實例到構造函數,你可以從控制器的構造器中完全移除這些以依賴。 然后,Laravel 5.0中使用的`App\Services\Registrar`不再被需要,你可以直接簡單拷貝粘貼其中的`validator`方法和`create`方法到`AuthController`中,這兩個方法中的代碼不需要做任何改動。不要忘記確認`Validator`和`User`在`AuthController`中是否已經被導入。 `PasswordController`不再需要在構造函數中聲明任何依賴,可以移除5.0中要求的兩個依賴。 ### 驗證 如果你重寫了`Controller`類中的`formatValidationErrors`方法,需要將類型提示由`Illuminate\Validation\Validator`改為`Illuminate\Contracts\Validation\Validator`。 ### Eloquent **create方法** Eloquent的`create`方法現在可以不傳入任何參數進行調用,如果你在模型中要重寫`create`方法,將`$attributes`參數的默認值改為數組: ~~~ public static function create(array $attributes = []){ // Your custom implementation } ~~~ **find方法** 如果你要在自己的模型中重寫`find`方法并在其中調用`parent::find()`,應該改由調用Eloquent查詢構建器的`find`方法: ~~~ public static function find($id, $columns = ['*']){ $model = static::query()->find($id, $columns); // ... return $model; } ~~~ **lists方法** `lists`方法現在返回一個`Collection`實例而不是包含Eloquent查詢結果的數組,如果你想將Collection轉化為數組,使用`all`方法: ~~~ User::lists('id')->all(); ~~~ > 注意:Query Builder的lists返回的仍然是數組。 **日期格式化** 以前,模型中的Eloquent日期字段存儲格式可以通過重寫`getDateFormat`方法來修改,現在依然可以這么做;但是為了更加方便可以在模型中簡單通過指定`$dateFormat`屬性來替代重寫方法。 在序列化模型到數組或JSON時日期格式也被應用到,當從Laravel 5.0遷移到5.1時,這將會改變JSON序列化的日期字段的格式。想要在序列化模型中設置指定的日期格式,你可以在模型中重寫`serializeDate(DateTime?$date)`方法,這樣就可以在不改變字段存儲格式的情況下對格式化序列化的Eloquent日期字段有著更加細粒度的控制。 ### Collection類 **sortBy方法** sortBy方法現在返回一個新的collection實例而不是改變已有的collection: ~~~ $collection = $collection->sortBy('name'); ~~~ **groupBy方法** `groupBy`方法現在為每個父級Collection中的item返回Collection實例,如果你想要將這些items轉化為數組,可以通過`map`方法實現: ~~~ $collection->groupBy('type')->map(function($item){ return $item->all(); }); ~~~ **lists方法** lists方法現在返回一個Collection實例而不是數組,如果你想要將Collection轉化數組,使用`all`方法: ~~~ $collection->lists('id')->all(); ~~~ ### 命令&處理器 `app/Commands`目錄現在被重命名為`app/Jobs`,但是并不需要將你的命令移動到新位置,你可以繼續使用`make:command`和`handler:command`?Artisan 命令生成自己的類。 同樣的,`app/Handlers`目錄被合并到`app/Listeners`目錄下,你也不必將已經存在的命令和事件處理器進行移動和重命名,你可以繼續使用`handler:event`命令生成事件處理器。 通過提供對Laravel 5.0目錄結構的向后兼容,你可以無縫升級應用到Laravel 5.1然后慢慢升級你的事件和命令到新的位置——在一個對你或你的團隊合適的時間。 ### Blade `createMatcher`,`createOpenMatcher`和`createPlainMatcher`方法已經從Blade編譯器中移除,可以使用新的`directive`方法來為5.1版的Blade創建自定義的指令。查閱擴展[Blade文檔](http://laravelacademy.org/post/79.html#extend-blade)了解詳情。 ### 測試 在tests/TestCase.php文件中新增protected屬性`$baseUrl`: ~~~ protected $baseUrl = 'http://localhost'; ~~~ ### 翻譯文件 用于為vendor包發布語言文件的默認目錄做了移動,所有vendor包語言文件從`resources/lang/packages/{locale}/{namespace}`移動到了`resources/lang/vendor/{namespace}/{locale}`目錄。例如,`Acme/Anvil`包的`acme/anvil::foo`英語語言文件將會從`resources/lang/packages/en/acme/anvil/foo.php`移動到`resources/lang/vendor/acme/anvil/en/foo.php`。 ### Amazon Web Services SDK 如果你正在使用AWS SQS隊列驅動或者AWS SES電子郵件驅動,需要升級AWS PHP SDK到3.0版本。 如果你正在使用Amazon S3文件系統驅動,需要通過Composer升級相應的文件系統包: * Amazon S3:?`league/flysystem-aws-s3-v3?~1.0` ### 廢棄 以下Laravel特性已經被廢棄并且會在2015年12月份的Laravel 5.2中被完全移除: * [中間件](http://laravelacademy.org/post/57.html)中的路由過濾器 * `Illuminate\Contracts\Routing\Middleware`,中間件中不再需要任何contract,`Illuminate\Contracts\Routing\TerminableMiddleware`被廢棄,在中間件中定義一個terminate方法替代實現該接口。 * `Illuminate\Contracts\Queue\ShouldBeQueued`?被廢棄,使用?`Illuminate\Contracts\Queue\ShouldQueue` * Iron.io “推入隊列” 被廢棄, 使用Iron.io 隊列和隊列監聽器. * `Illuminate\Foundation\Bus\DispatchesCommands`?trait 被廢棄并被重命名為`Illuminate\Foundation\Bus\DispatchesJobs`. * `Illuminate\Container\BindingResolutionException`?被移動到`Illuminate\Contracts\Container\BindingResolutionException`. * 服務容器的?`bindShared`?方法被廢棄,使用`singleton`?方法。 * Eloquent和query builder的?`pluck`?方法被廢棄并重命名為`value`. * Collection的?`fetch`?方法被廢棄,使用?`pluck`?方法. * `array_fetch`?幫助函數被廢棄, 使用`array_pluck`
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看