久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

覆蓋 Laravel 5 輔助函數

Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數)
本文介紹了覆蓋 Laravel 5 輔助函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我經常使用 response() 助手,我只是將數據和一條消息返回給用戶.現在我還必須包含 http 狀態代碼,但我不想更改每個響應(無論如何這可能很糟糕).

I'm using the response() helper very often and I just return the data with a message to the user. Now I have to include the http status code as well, but I don't want to change every response (which is likely bad anyway).

所以我試圖通過在 app/Http/helpers.php 中創建我自己的 helpers.php 來覆蓋 response() 輔助函數代碼>.

So I'm trying to overwrite the response() helper function by creating my own helpers.php within app/Http/helpers.php.

當我將它添加到我的 Composer 文件時,它會首先從框架自動加載當前的 helpers.php,當我在 autload 包含在 bootstrap/global.php 之前添加它時,我將無法使用 app() 和其他 Laravel 函數.

When I add it to my composer files, it does autoload the current helpers.php from the framework first and when I add it before the autload include in bootstrap/global.php I wont be able to use the app() and other Laravel functions.

我該如何解決這個問題?我只想在響應數組中包含狀態代碼.

How would I be able to solve this issue? I just want to include the status code as well in the response array.

推薦答案

所有 Laravel 輔助函數都用這個邏輯編寫

All Laravel helper functions written with this logic

if ( ! function_exists('response'))
{
    function response($content = '', $status = 200, array $headers = array())
    {
         // function body
    }
}

首先 Laravel 檢查這個函數是否存在,如果存在,Laravel 不會再次定義這個函數(否則會拋出致命錯誤).因此,如果您將在自動加載器包含 vendor/laravel/framework/src/Illuminate/Foundation/helpers.php 文件之前定義您的函數,您可以定義自定義響應函數.

for first Laravel check is this function exists, if it exists, Laravel will not define this function again(otherwise it will throw fatal error). So if you will define your function before autoloader include vendor/laravel/framework/src/Illuminate/Foundation/helpers.php file, you can define your custom response function.

不幸的是,沒有辦法說 composer 首先加載你的 autoload.files 部分,然后是 laravel autoload.files.但是你可以做一些小黑客......

Unfortunately there is no way to say composer load first your autoload.files section, then laravel autoload.files. But you can do small hack ...

打開 bootstrap/autoload.php 文件并在自動加載器之前包含您的文件

open bootstrap/autoload.php file and include your file before autoloader

// file with your custom helper functions
require __DIR__.'/../app/app/Http/helpers.php'; 
require __DIR__.'/../vendor/autoload.php';

這篇關于覆蓋 Laravel 5 輔助函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應內容必須是實現 __toString()、“boolean和“boolean的字符串或對象.移動到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
How to set and get Cookie in laravel(如何在 Laravel 中設置和獲取 Cookie)
主站蜘蛛池模板: 久久国产欧美日韩精品 | 亚洲欧美一区二区三区视频 | 毛片在线看片 | 精品国产一区二区久久 | 99精品在线 | 国产精品极品美女在线观看免费 | 中文字幕一区二区三区在线观看 | 91免费观看视频 | 在线观看av不卡 | 视频一区在线播放 | 99精品免费久久久久久日本 | 精品一区二区三区中文字幕 | 亚洲国产精品久久久 | 国产黄色大片在线观看 | 欧美成人激情 | www国产亚洲精品 | 成人欧美一区二区三区视频xxx | 国产成人免费 | 国产欧美一区二区三区免费 | 中文字幕亚洲国产 | 亚洲精品在线免费播放 | 99精品一级欧美片免费播放 | 亚洲福利一区二区 | 久久国产亚洲 | 久久国产一区二区 | 日日天天 | www.av在线| 亚州毛片 | 男女羞羞视频在线看 | 欧美激情精品久久久久久变态 | www久久99 | 在线视频 中文字幕 | 风间由美一区二区三区在线观看 | 草樱av| 亚洲一区在线日韩在线深爱 | 在线播放亚洲 | 久久视频一区 | 91亚洲精华国产 | 91久久久久久久 | 国产欧美精品区一区二区三区 | 99久久久久国产精品免费 |