# laravel macros https://www.youtube.com/watch?v=XQefAcs4qf0 ## 介紹 擴張class方法 laravel有這個  利用_call方法 可以自訂語法 ex Macro excel之類的套件就也有支持   ## 舉例 Ex 旅人的collection pagint ``` //分頁自定義 /** * Paginate a standard Laravel Collection. * * @param int $perPage * @param int $total * @param int $page * @param string $pageName * @return array */ Collection::macro('paginate', function ($perPage, $total = null, $page = null, $pageName = 'page') { $page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName); return new LengthAwarePaginator( $this->forPage($page, $perPage), $total ?: $this->count(), $perPage, $page, [ 'path' => LengthAwarePaginator::resolveCurrentPath(), 'pageName' => $pageName, ] ); }); ``` excel的 ###### tags: `Laravel`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up